Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: webkit/glue/plugins/webplugin_delegate_impl_mac.mm

Issue 165344: Add an UpdateContext call to WebPluginDelegateImpl on the Mac. (Closed)
Patch Set: Stripped down to Mac-only Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webkit/glue/plugins/webplugin_delegate_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "webkit/glue/plugins/webplugin_delegate_impl.h" 7 #include "webkit/glue/plugins/webplugin_delegate_impl.h"
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 bool start_result = instance_->Start(url, argn, argv, argc, load_manually); 124 bool start_result = instance_->Start(url, argn, argv, argc, load_manually);
125 125
126 NPAPI::PluginInstance::SetInitializingInstance(old_instance); 126 NPAPI::PluginInstance::SetInitializingInstance(old_instance);
127 127
128 if (!start_result) 128 if (!start_result)
129 return false; 129 return false;
130 130
131 FakePluginWindowTracker* window_tracker = 131 FakePluginWindowTracker* window_tracker =
132 FakePluginWindowTracker::SharedInstance(); 132 FakePluginWindowTracker::SharedInstance();
133 cg_context_.window = window_tracker->GenerateFakeWindowForDelegate(this); 133 cg_context_.window = window_tracker->GenerateFakeWindowForDelegate(this);
134 cg_context_.context = NULL;
134 Rect window_bounds = { 0, 0, window_rect_.height(), window_rect_.width() }; 135 Rect window_bounds = { 0, 0, window_rect_.height(), window_rect_.width() };
135 SetWindowBounds(cg_context_.window, kWindowContentRgn, &window_bounds); 136 SetWindowBounds(cg_context_.window, kWindowContentRgn, &window_bounds);
136 window_.window = &cg_context_; 137 window_.window = &cg_context_;
137 window_.type = NPWindowTypeWindow; 138 window_.type = NPWindowTypeWindow;
138 139
139 plugin->SetWindow(NULL); 140 plugin->SetWindow(NULL);
140 plugin_url_ = url.spec(); 141 plugin_url_ = url.spec();
141 142
142 MessageLoop::current()->PostDelayedTask(FROM_HERE, 143 MessageLoop::current()->PostDelayedTask(FROM_HERE,
143 null_event_factory_.NewRunnableMethod( 144 null_event_factory_.NewRunnableMethod(
(...skipping 15 matching lines...) Expand all
159 } 160 }
160 } 161 }
161 162
162 void WebPluginDelegateImpl::UpdateGeometry( 163 void WebPluginDelegateImpl::UpdateGeometry(
163 const gfx::Rect& window_rect, 164 const gfx::Rect& window_rect,
164 const gfx::Rect& clip_rect) { 165 const gfx::Rect& clip_rect) {
165 DCHECK(windowless_); 166 DCHECK(windowless_);
166 WindowlessUpdateGeometry(window_rect, clip_rect); 167 WindowlessUpdateGeometry(window_rect, clip_rect);
167 } 168 }
168 169
170 void WebPluginDelegateImpl::UpdateContext(CGContextRef context) {
171 // Flash on the Mac apparently caches the context from the struct it recieves
172 // in NPP_SetWindow, and continue to use it even when the contents of the
173 // struct have changed, so we need to call NPP_SetWindow again if the context
174 // changes.
175 if (context != cg_context_.context) {
176 cg_context_.context = context;
177 WindowlessSetWindow(true);
178 }
179 }
180
169 void WebPluginDelegateImpl::Paint(CGContextRef context, const gfx::Rect& rect) { 181 void WebPluginDelegateImpl::Paint(CGContextRef context, const gfx::Rect& rect) {
170 DCHECK(windowless_); 182 DCHECK(windowless_);
171 WindowlessPaint(context, rect); 183 WindowlessPaint(context, rect);
172 } 184 }
173 185
174 void WebPluginDelegateImpl::Print(CGContextRef context) { 186 void WebPluginDelegateImpl::Print(CGContextRef context) {
175 // Disabling the call to NPP_Print as it causes a crash in 187 // Disabling the call to NPP_Print as it causes a crash in
176 // flash in some cases. In any case this does not work as expected 188 // flash in some cases. In any case this does not work as expected
177 // as the EMF meta file dc passed in needs to be created with the 189 // as the EMF meta file dc passed in needs to be created with the
178 // the plugin window dc as its sibling dc and the window rect 190 // the plugin window dc as its sibling dc and the window rect
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 254
243 if (window_rect_ != window_rect) { 255 if (window_rect_ != window_rect) {
244 window_rect_ = window_rect; 256 window_rect_ = window_rect;
245 257
246 WindowlessSetWindow(true); 258 WindowlessSetWindow(true);
247 } 259 }
248 } 260 }
249 261
250 void WebPluginDelegateImpl::WindowlessPaint(gfx::NativeDrawingContext context, 262 void WebPluginDelegateImpl::WindowlessPaint(gfx::NativeDrawingContext context,
251 const gfx::Rect& damage_rect) { 263 const gfx::Rect& damage_rect) {
264 // If we somehow get a paint before we've set up the plugin window, bail.
265 if (!cg_context_.context)
266 return;
267 DCHECK(cg_context_.context == context);
268
252 static StatsRate plugin_paint("Plugin.Paint"); 269 static StatsRate plugin_paint("Plugin.Paint");
253 StatsScope<StatsRate> scope(plugin_paint); 270 StatsScope<StatsRate> scope(plugin_paint);
254 271
255 // We save and restore the NSGraphicsContext state in case the plugin uses 272 // We save and restore the NSGraphicsContext state in case the plugin uses
256 // Cocoa drawing. 273 // Cocoa drawing.
257 [NSGraphicsContext saveGraphicsState]; 274 [NSGraphicsContext saveGraphicsState];
258 [NSGraphicsContext setCurrentContext:[NSGraphicsContext 275 [NSGraphicsContext setCurrentContext:[NSGraphicsContext
259 graphicsContextWithGraphicsPort:context 276 graphicsContextWithGraphicsPort:context
260 flipped:YES]]; 277 flipped:YES]];
261 CGContextSaveGState(context); 278 CGContextSaveGState(context);
262 279
263 cg_context_.context = context;
264 if (window_.window == NULL)
265 windowless_needs_set_window_ = true;
266
267 window_.window = &cg_context_;
268
269 if (windowless_needs_set_window_)
270 WindowlessSetWindow(false);
271
272 NPEvent paint_event; 280 NPEvent paint_event;
273 paint_event.what = updateEvt; 281 paint_event.what = updateEvt;
274 paint_event.message = reinterpret_cast<uint32>(cg_context_.window); 282 paint_event.message = reinterpret_cast<uint32>(cg_context_.window);
275 paint_event.when = TickCount(); 283 paint_event.when = TickCount();
276 paint_event.where.h = 0; 284 paint_event.where.h = 0;
277 paint_event.where.v = 0; 285 paint_event.where.v = 0;
278 paint_event.modifiers = 0; 286 paint_event.modifiers = 0;
279 instance()->NPP_HandleEvent(&paint_event); 287 instance()->NPP_HandleEvent(&paint_event);
280 288
281 CGContextRestoreGState(context); 289 CGContextRestoreGState(context);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 return; 324 return;
317 325
318 window_.clipRect.top = 0; 326 window_.clipRect.top = 0;
319 window_.clipRect.left = 0; 327 window_.clipRect.left = 0;
320 window_.clipRect.bottom = window_rect_.height(); 328 window_.clipRect.bottom = window_rect_.height();
321 window_.clipRect.right = window_rect_.width(); 329 window_.clipRect.right = window_rect_.width();
322 window_.height = window_rect_.height(); 330 window_.height = window_rect_.height();
323 window_.width = window_rect_.width(); 331 window_.width = window_rect_.width();
324 window_.x = 0; 332 window_.x = 0;
325 window_.y = 0; 333 window_.y = 0;
326 window_.type = NPWindowTypeWindow;
327
328 if (!force_set_window)
329 // Reset this flag before entering the instance in case of side-effects.
330 windowless_needs_set_window_ = false;
331 334
332 UpdateDummyWindowBoundsWithOffset(cg_context_.window, window_rect_.x(), 335 UpdateDummyWindowBoundsWithOffset(cg_context_.window, window_rect_.x(),
333 window_rect_.y(), window_rect_.width(), 336 window_rect_.y(), window_rect_.width(),
334 window_rect_.height()); 337 window_rect_.height());
335 338
336 if (!force_set_window)
337 windowless_needs_set_window_ = false;
338 NPError err = instance()->NPP_SetWindow(&window_); 339 NPError err = instance()->NPP_SetWindow(&window_);
339 DCHECK(err == NPERR_NO_ERROR); 340 DCHECK(err == NPERR_NO_ERROR);
340 } 341 }
341 342
342 void WebPluginDelegateImpl::SetFocus() { 343 void WebPluginDelegateImpl::SetFocus() {
343 NPEvent focus_event = { 0 }; 344 NPEvent focus_event = { 0 };
344 focus_event.what = NPEventType_GetFocusEvent; 345 focus_event.what = NPEventType_GetFocusEvent;
345 focus_event.when = TickCount(); 346 focus_event.when = TickCount();
346 instance()->NPP_HandleEvent(&focus_event); 347 instance()->NPP_HandleEvent(&focus_event);
347 } 348 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // window structure or the menu bar, but neither should be involved here. 473 // window structure or the menu bar, but neither should be involved here.
473 g_current_x_offset = event.globalX - event.windowX; 474 g_current_x_offset = event.globalX - event.windowX;
474 g_current_y_offset = event.globalY - event.windowY + 22; 475 g_current_y_offset = event.globalY - event.windowY + 22;
475 476
476 UpdateDummyWindowBoundsWithOffset(window, event.windowX - event.x, 477 UpdateDummyWindowBoundsWithOffset(window, event.windowX - event.x,
477 event.windowY - event.y, 0, 0); 478 event.windowY - event.y, 0, 0);
478 } 479 }
479 480
480 bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, 481 bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event,
481 WebCursorInfo* cursor) { 482 WebCursorInfo* cursor) {
483 // If we somehow get an event before we've set up the plugin window, bail.
484 if (!cg_context_.context)
485 return false;
482 DCHECK(windowless_) << "events should only be received in windowless mode"; 486 DCHECK(windowless_) << "events should only be received in windowless mode";
483 DCHECK(cursor != NULL); 487 DCHECK(cursor != NULL);
484 488
485 NPEvent np_event = {0}; 489 NPEvent np_event = {0};
486 if (!NPEventFromWebInputEvent(event, &np_event)) { 490 if (!NPEventFromWebInputEvent(event, &np_event)) {
487 return false; 491 return false;
488 } 492 }
489 np_event.when = TickCount(); 493 np_event.when = TickCount();
490 if (np_event.what == nullEvent) { 494 if (np_event.what == nullEvent) {
491 last_mouse_x_ = np_event.where.h; 495 last_mouse_x_ = np_event.where.h;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 np_event.modifiers |= btnState; 552 np_event.modifiers |= btnState;
549 np_event.where.h = last_mouse_x_; 553 np_event.where.h = last_mouse_x_;
550 np_event.where.v = last_mouse_y_; 554 np_event.where.v = last_mouse_y_;
551 instance()->NPP_HandleEvent(&np_event); 555 instance()->NPP_HandleEvent(&np_event);
552 556
553 MessageLoop::current()->PostDelayedTask(FROM_HERE, 557 MessageLoop::current()->PostDelayedTask(FROM_HERE,
554 null_event_factory_.NewRunnableMethod( 558 null_event_factory_.NewRunnableMethod(
555 &WebPluginDelegateImpl::OnNullEvent), 559 &WebPluginDelegateImpl::OnNullEvent),
556 kPluginIdleThrottleDelayMs); 560 kPluginIdleThrottleDelayMs);
557 } 561 }
OLDNEW
« no previous file with comments | « webkit/glue/plugins/webplugin_delegate_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698