Class: Fzeet::WebBrowser

Inherits:
Windows::WebBrowser
  • Object
show all
Defined in:
lib/fzeet/windows/shdocvw.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ WebBrowser

Returns a new instance of WebBrowser.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/fzeet/windows/shdocvw.rb', line 120

def initialize(parent)
  @parent = parent

  @oips = Windows::OleInPlaceSite.new

  @oips.instance_variable_set(:@browser, self)

  class << @oips
    attr_reader :browser

    def CanInPlaceActivate
      Windows::S_OK
    end

    def GetWindow(phwnd)
      phwnd.write_pointer(browser.parent.handle)

      Windows::S_OK
    end

    def GetWindowContext(pframe, pdoc, prPos, prClip, pinfo)
      pframe.write_pointer(0)
      pdoc.write_pointer(0)
      Windows.GetClientRect(browser.parent.handle, prPos)
      Windows.GetClientRect(browser.parent.handle, prClip)

      Windows::S_OK
    end

    def OnPosRectChange(prPos)
      browser.QueryInstance(Windows::OleInPlaceObject) { |oipo|
        oipo.SetObjectRects(prPos, prPos)
      }

      Windows::S_OK
    end
  end

  @ocs = Windows::OleClientSite.new

  @ocs.instance_variable_set(:@browser, self)

  class << @ocs
    attr_reader :browser

    def QueryInterface(piid, ppv)
      if Windows::GUID.new(piid) == Windows::IOleInPlaceSite::IID
        ppv.write_pointer(browser.oips); browser.oips.AddRef

        return Windows::S_OK
      end

      super
    end
  end

  super()

  @events = Windows::WebBrowserEvents.new

  @events.instance_variable_set(:@browser, self)

  class << @events
    attr_reader :browser

    (self::VTBL.members - Windows::IDispatch::VTBL.members).each { |name|
      define_method(name) { |dispParams|
        (handlers = browser.handlers && browser.handlers[name]) && handlers.each { |handler|
          (handler.arity == 0) ? handler.call : handler.call(dispParams)
        }
      }
    }
  end

  QueryInstance(Windows::ConnectionPointContainer) { |cpc|
    FFI::MemoryPointer.new(:pointer) { |pcp|
      cpc.FindConnectionPoint(Windows::WebBrowserEvents::IID, pcp)

      @cp = Windows::ConnectionPoint.new(pcp.read_pointer)
    }
  }

  @cookie = nil
  FFI::MemoryPointer.new(:ulong) { |p| @cp.Advise(@events, p); @cookie = p.get_ulong(0) }

  QueryInstance(Windows::OleObject) { |oo|
    oo.SetClientSite(@ocs)
    oo.DoVerb(Windows::OLEIVERB_INPLACEACTIVATE, nil, @ocs, 0, @parent.handle, @parent.rect)
  }

  @parent.
    on(:size) {
      r = @parent.rect

      put_Top(r[:top]); put_Left(r[:left]); put_Width(r[:right]); put_Height(r[:bottom])
    }.

    on(:destroy) {
      @oips.Release
      @ocs.Release
      @cp.Unadvise(@cookie)
      @events.Release
      @cp.Release
      Release()
    }.

    instance_variable_set(:@__WebBrowser__, self)
end

Instance Attribute Details

#cpObject (readonly)

Returns the value of attribute cp.



229
230
231
# File 'lib/fzeet/windows/shdocvw.rb', line 229

def cp
  @cp
end

#eventsObject (readonly)

Returns the value of attribute events.



229
230
231
# File 'lib/fzeet/windows/shdocvw.rb', line 229

def events
  @events
end

#handlersObject (readonly)

Returns the value of attribute handlers.



229
230
231
# File 'lib/fzeet/windows/shdocvw.rb', line 229

def handlers
  @handlers
end

#ocsObject (readonly)

Returns the value of attribute ocs.



229
230
231
# File 'lib/fzeet/windows/shdocvw.rb', line 229

def ocs
  @ocs
end

#oipsObject (readonly)

Returns the value of attribute oips.



229
230
231
# File 'lib/fzeet/windows/shdocvw.rb', line 229

def oips
  @oips
end

#parentObject (readonly)

Returns the value of attribute parent.



229
230
231
# File 'lib/fzeet/windows/shdocvw.rb', line 229

def parent
  @parent
end

Instance Method Details

#backObject



247
# File 'lib/fzeet/windows/shdocvw.rb', line 247

def back; GoBack(); self; rescue; self end

#documentObject



254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/fzeet/windows/shdocvw.rb', line 254

def document
  disp = nil

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

    disp = Windows::Dispatch.new(pdisp.read_pointer)

    return disp.QueryInstance(Windows::HTMLDocument2)
  }
ensure
  disp.Release if disp
end

#forwardObject



248
# File 'lib/fzeet/windows/shdocvw.rb', line 248

def forward; GoForward(); self; rescue; self end

#goto(where) ⇒ Object



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

def goto(where)
  where = Windows.SysAllocString("#{where}\0".encode('utf-16le'))

  Navigate(where, nil, nil, nil, nil)

  self
ensure
  Windows.SysFreeString(where)
end

#homeObject



249
# File 'lib/fzeet/windows/shdocvw.rb', line 249

def home; GoHome(); self end

#on(event, &block) ⇒ Object



231
232
233
234
235
# File 'lib/fzeet/windows/shdocvw.rb', line 231

def on(event, &block)
  ((@handlers ||= {})[event] ||= []) << block

  self
end

#refreshObject



252
# File 'lib/fzeet/windows/shdocvw.rb', line 252

def refresh; Refresh(); self end

#searchObject



250
# File 'lib/fzeet/windows/shdocvw.rb', line 250

def search; GoSearch(); self end