Class: Fzeet::Windows::HTMLDocument2

Inherits:
Object
  • Object
show all
Defined in:
lib/fzeet/windows/mshtml/Common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#handlersObject (readonly)

Returns the value of attribute handlers.



132
133
134
# File 'lib/fzeet/windows/mshtml/Common.rb', line 132

def handlers
  @handlers
end

Instance Method Details

#allObject



221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/fzeet/windows/mshtml/Common.rb', line 221

def all
	pdisp = nil

	FFI::MemoryPointer.new(:pointer) { |pdisp|
		get_all(pdisp)

		disp = Dispatch.new(pdisp.read_pointer)

		return disp.QueryInstance(HTMLElementCollection)
	}
ensure
	pdisp.Release if pdisp
end

#createElement(tag) ⇒ Object



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/fzeet/windows/mshtml/Common.rb', line 237

def createElement(tag)
	bstr = nil

	FFI::MemoryPointer.new(:pointer) { |pelem|
		old_createElement(bstr = Windows.SysAllocString("#{tag}\0".encode('utf-16le')), pelem)

		return HTMLElement.new(pelem.read_pointer)
	}
ensure
	Windows.SysFreeString(bstr)
end

#old_createElementObject



235
# File 'lib/fzeet/windows/mshtml/Common.rb', line 235

alias old_createElement createElement

#on(event, &block) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/fzeet/windows/mshtml/Common.rb', line 134

def on(event, &block)
	_event, _block = if event == :ready
		[:readystatechange, -> *args { next unless readyState == 'complete'; block.(*args) }]
	else
		[event, block]
	end

	((@handlers ||= {})[_event] ||= []) << _block
	@dcallbacks ||= []

	send("put_on#{_event}", VARIANT.new.tap { |v|
		v[:vt] = VT_DISPATCH

		v[:pdispVal] = @dcallbacks.push(DCallback.new.tap { |dcb|
			dcb.instance_variable_set(:@document, self)
			dcb.instance_variable_set(:@event, _event)

			def dcb.Invoke(*args)
				@document.handlers[@event].each { |handler|
					(handler.arity == 0) ? handler.call : handler.call(*args)
				}

				S_OK
			end
		}).last
	}) unless @handlers[_event].length > 1

	self
end

#parentWindowObject Also known as: window



164
165
166
167
168
169
170
# File 'lib/fzeet/windows/mshtml/Common.rb', line 164

def parentWindow
	FFI::MemoryPointer.new(:pointer) { |pwindow|
		get_parentWindow(pwindow)

		return HTMLWindow2.new(pwindow.read_pointer)
	}
end

#readyStateObject



213
214
215
216
217
218
219
# File 'lib/fzeet/windows/mshtml/Common.rb', line 213

def readyState
	FFI::MemoryPointer.new(:pointer) { |pstate|
		get_readyState(pstate)

		return Windows.WCSTOMBS(pstate.read_pointer)
	}
end

#requestObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/fzeet/windows/mshtml/Common.rb', line 177

def request
	disp = nil

	window.QueryInstance(HTMLWindow5) { |htmlwindow5|
		disp = Dispatch.new(VARIANT.new.tap { |v| htmlwindow5.get_XMLHttpRequest(v) }[:pdispVal])

		disp.QueryInstance(HTMLXMLHttpRequestFactory) { |factory|
			FFI::MemoryPointer.new(:pointer) { |prequest|
				factory.create(prequest)

				return HTMLXMLHttpRequest.new(prequest.read_pointer)
			}
		}
	}
ensure
	disp.Release if disp
end

#request=(enabled) ⇒ Object



175
# File 'lib/fzeet/windows/mshtml/Common.rb', line 175

def request=(enabled) Windows.DetonateHresult(:CoInternetSetFeatureEnabled, FEATURE_XMLHTTP, SET_FEATURE_ON_PROCESS, (enabled) ? 1 : 0) end

#request?Boolean

Returns:

  • (Boolean)


174
# File 'lib/fzeet/windows/mshtml/Common.rb', line 174

def request?; Windows.CoInternetIsFeatureEnabled(FEATURE_XMLHTTP, GET_FEATURE_FROM_PROCESS) == S_OK end

#xrequestObject



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/fzeet/windows/mshtml/Common.rb', line 195

def xrequest
	disp = nil

	window.QueryInstance(HTMLWindow6) { |htmlwindow6|
		disp = Dispatch.new(VARIANT.new.tap { |v| htmlwindow6.get_XDomainRequest(v) }[:pdispVal])

		disp.QueryInstance(HTMLXDomainRequestFactory) { |factory|
			FFI::MemoryPointer.new(:pointer) { |pxrequest|
				factory.create(pxrequest)

				return HTMLXDomainRequest.new(pxrequest.read_pointer)
			}
		}
	}
ensure
	disp.Release if disp
end