OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/task.h" | 15 #include "base/task.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "chrome/browser/renderer_host/backing_store_skia.h" | |
17 #include "chrome/browser/renderer_host/backing_store_x.h" | 18 #include "chrome/browser/renderer_host/backing_store_x.h" |
18 #include "chrome/browser/renderer_host/render_widget_host.h" | 19 #include "chrome/browser/renderer_host/render_widget_host.h" |
19 #include "chrome/common/native_web_keyboard_event.h" | 20 #include "chrome/common/native_web_keyboard_event.h" |
20 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
21 #include "chrome/common/result_codes.h" | 22 #include "chrome/common/result_codes.h" |
22 #include "gfx/canvas.h" | 23 #include "gfx/canvas.h" |
24 #include "gfx/canvas_skia.h" | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact ory.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact ory.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
25 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" | 27 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" |
26 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/x/x11_util.h" | 29 #include "ui/base/x/x11_util.h" |
28 #include "views/event.h" | 30 #include "views/event.h" |
29 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
30 #include "views/widget/widget_gtk.h" | 32 #include "views/widget/widget_gtk.h" |
31 | 33 |
32 static const int kMaxWindowWidth = 4000; | 34 static const int kMaxWindowWidth = 4000; |
33 static const int kMaxWindowHeight = 4000; | 35 static const int kMaxWindowHeight = 4000; |
34 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 36 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
37 static const char* kBackingStoreSkiaSwitch = "use-backing-store-skia"; | |
agl
2011/02/07 17:26:47
use |char kBackingStoreSkiaSwitch[]| to save a rel
sadrul
2011/02/07 18:22:38
Done.
| |
35 | 38 |
36 using WebKit::WebInputEventFactory; | 39 using WebKit::WebInputEventFactory; |
37 using WebKit::WebMouseWheelEvent; | 40 using WebKit::WebMouseWheelEvent; |
38 using WebKit::WebTouchEvent; | 41 using WebKit::WebTouchEvent; |
39 | 42 |
40 namespace { | 43 namespace { |
41 | 44 |
45 bool UsingBackingStoreSkia() { | |
46 static bool decided = false; | |
47 static bool use_skia = false; | |
48 if (!decided) { | |
49 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
50 use_skia = (cmdline && cmdline->HasSwitch(kBackingStoreSkiaSwitch)); | |
51 decided = true; | |
52 } | |
53 | |
54 return use_skia; | |
55 } | |
56 | |
42 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { | 57 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { |
43 int modifiers = 0; | 58 int modifiers = 0; |
44 | 59 |
45 if (event.IsShiftDown()) | 60 if (event.IsShiftDown()) |
46 modifiers |= WebKit::WebInputEvent::ShiftKey; | 61 modifiers |= WebKit::WebInputEvent::ShiftKey; |
47 if (event.IsControlDown()) | 62 if (event.IsControlDown()) |
48 modifiers |= WebKit::WebInputEvent::ControlKey; | 63 modifiers |= WebKit::WebInputEvent::ControlKey; |
49 if (event.IsAltDown()) | 64 if (event.IsAltDown()) |
50 modifiers |= WebKit::WebInputEvent::AltKey; | 65 modifiers |= WebKit::WebInputEvent::AltKey; |
51 if (event.IsCapsLockDown()) | 66 if (event.IsCapsLockDown()) |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 | 336 |
322 bool RenderWidgetHostViewViews::IsPopup() { | 337 bool RenderWidgetHostViewViews::IsPopup() { |
323 return popup_type_ != WebKit::WebPopupTypeNone; | 338 return popup_type_ != WebKit::WebPopupTypeNone; |
324 } | 339 } |
325 | 340 |
326 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( | 341 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( |
327 const gfx::Size& size) { | 342 const gfx::Size& size) { |
328 gfx::NativeView nview = GetInnerNativeView(); | 343 gfx::NativeView nview = GetInnerNativeView(); |
329 if (!nview) | 344 if (!nview) |
330 return NULL; | 345 return NULL; |
331 return new BackingStoreX(host_, size, | 346 |
332 ui::GetVisualFromGtkWidget(nview), | 347 if (UsingBackingStoreSkia()) |
agl
2011/02/07 17:26:47
the style guide lets you do this, although I would
sadrul
2011/02/07 18:22:38
Done.
| |
333 gtk_widget_get_visual(nview)->depth); | 348 return new BackingStoreSkia(host_, size); |
349 else | |
350 return new BackingStoreX(host_, size, | |
351 ui::GetVisualFromGtkWidget(nview), | |
352 gtk_widget_get_visual(nview)->depth); | |
334 } | 353 } |
335 | 354 |
336 gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { | 355 gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { |
337 // TODO(sad): Ideally this function should be equivalent to GetNativeView, and | 356 // TODO(sad): Ideally this function should be equivalent to GetNativeView, and |
338 // WidgetGtk-specific function call should not be necessary. | 357 // WidgetGtk-specific function call should not be necessary. |
339 views::WidgetGtk* widget = static_cast<views::WidgetGtk*>(GetWidget()); | 358 views::WidgetGtk* widget = static_cast<views::WidgetGtk*>(GetWidget()); |
340 return widget ? widget->window_contents() : NULL; | 359 return widget ? widget->window_contents() : NULL; |
341 } | 360 } |
342 | 361 |
343 gfx::NativeView RenderWidgetHostViewViews::GetNativeView() { | 362 gfx::NativeView RenderWidgetHostViewViews::GetNativeView() { |
(...skipping 29 matching lines...) Expand all Loading... | |
373 GdkWindow* window = GetInnerNativeView()->window; | 392 GdkWindow* window = GetInnerNativeView()->window; |
374 DCHECK(!about_to_validate_and_paint_); | 393 DCHECK(!about_to_validate_and_paint_); |
375 | 394 |
376 // TODO(anicolao): get the damage somehow | 395 // TODO(anicolao): get the damage somehow |
377 // invalid_rect_ = damage_rect; | 396 // invalid_rect_ = damage_rect; |
378 invalid_rect_ = bounds(); | 397 invalid_rect_ = bounds(); |
379 gfx::Point origin; | 398 gfx::Point origin; |
380 ConvertPointToWidget(this, &origin); | 399 ConvertPointToWidget(this, &origin); |
381 | 400 |
382 about_to_validate_and_paint_ = true; | 401 about_to_validate_and_paint_ = true; |
383 BackingStoreX* backing_store = static_cast<BackingStoreX*>( | 402 BackingStore* backing_store = host_->GetBackingStore(true); |
384 host_->GetBackingStore(true)); | |
385 // Calling GetBackingStore maybe have changed |invalid_rect_|... | 403 // Calling GetBackingStore maybe have changed |invalid_rect_|... |
386 about_to_validate_and_paint_ = false; | 404 about_to_validate_and_paint_ = false; |
387 | 405 |
388 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); | 406 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); |
389 paint_rect = paint_rect.Intersect(invalid_rect_); | 407 paint_rect = paint_rect.Intersect(invalid_rect_); |
390 | 408 |
391 if (backing_store) { | 409 if (backing_store) { |
392 // Only render the widget if it is attached to a window; there's a short | 410 // Only render the widget if it is attached to a window; there's a short |
393 // period where this object isn't attached to a window but hasn't been | 411 // period where this object isn't attached to a window but hasn't been |
394 // Destroy()ed yet and it receives paint messages... | 412 // Destroy()ed yet and it receives paint messages... |
395 if (window) { | 413 if (window) { |
396 if (!visually_deemphasized_) { | 414 if (!visually_deemphasized_) { |
397 // In the common case, use XCopyArea. We don't draw more than once, so | 415 // In the common case, use XCopyArea. We don't draw more than once, so |
398 // we don't need to double buffer. | 416 // we don't need to double buffer. |
399 backing_store->XShowRect(origin, | 417 |
400 paint_rect, ui::GetX11WindowFromGdkWindow(window)); | 418 if (UsingBackingStoreSkia()) { |
401 } else { | 419 static_cast<BackingStoreSkia*>(backing_store)->SkiaShowRect( |
420 gfx::Point(paint_rect.x(), paint_rect.y()), canvas); | |
421 } else { | |
422 static_cast<BackingStoreX*>(backing_store)->XShowRect(origin, | |
423 paint_rect, ui::GetX11WindowFromGdkWindow(window)); | |
424 } | |
425 } else if (!UsingBackingStoreSkia()) { | |
402 // If the grey blend is showing, we make two drawing calls. Use double | 426 // If the grey blend is showing, we make two drawing calls. Use double |
403 // buffering to prevent flicker. Use CairoShowRect because XShowRect | 427 // buffering to prevent flicker. Use CairoShowRect because XShowRect |
404 // shortcuts GDK's double buffering. | 428 // shortcuts GDK's double buffering. |
405 GdkRectangle rect = { paint_rect.x(), paint_rect.y(), | 429 GdkRectangle rect = { paint_rect.x(), paint_rect.y(), |
406 paint_rect.width(), paint_rect.height() }; | 430 paint_rect.width(), paint_rect.height() }; |
407 gdk_window_begin_paint_rect(window, &rect); | 431 gdk_window_begin_paint_rect(window, &rect); |
408 | 432 |
409 backing_store->CairoShowRect(paint_rect, GDK_DRAWABLE(window)); | 433 static_cast<BackingStoreX*>(backing_store)->CairoShowRect( |
434 paint_rect, GDK_DRAWABLE(window)); | |
410 | 435 |
411 cairo_t* cr = gdk_cairo_create(window); | 436 cairo_t* cr = gdk_cairo_create(window); |
412 gdk_cairo_rectangle(cr, &rect); | 437 gdk_cairo_rectangle(cr, &rect); |
413 cairo_set_source_rgba(cr, 0, 0, 0, 0.7); | 438 cairo_set_source_rgba(cr, 0, 0, 0, 0.7); |
414 cairo_fill(cr); | 439 cairo_fill(cr); |
415 cairo_destroy(cr); | 440 cairo_destroy(cr); |
416 | 441 |
417 gdk_window_end_paint(window); | 442 gdk_window_end_paint(window); |
443 } else { | |
444 // TODO(sad) | |
445 NOTIMPLEMENTED(); | |
agl
2011/02/07 17:26:47
NOTREACHED()?
sadrul
2011/02/07 18:22:38
It's not clear to me when |visually_deemphasized_|
| |
418 } | 446 } |
419 } | 447 } |
420 if (!whiteout_start_time_.is_null()) { | 448 if (!whiteout_start_time_.is_null()) { |
421 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - | 449 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - |
422 whiteout_start_time_; | 450 whiteout_start_time_; |
423 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); | 451 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); |
424 | 452 |
425 // Reset the start time to 0 so that we start recording again the next | 453 // Reset the start time to 0 so that we start recording again the next |
426 // time the backing store is NULL... | 454 // time the backing store is NULL... |
427 whiteout_start_time_ = base::TimeTicks(); | 455 whiteout_start_time_ = base::TimeTicks(); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
583 } | 611 } |
584 #endif | 612 #endif |
585 | 613 |
586 ShowCurrentCursor(); | 614 ShowCurrentCursor(); |
587 GetRenderWidgetHost()->GotFocus(); | 615 GetRenderWidgetHost()->GotFocus(); |
588 } | 616 } |
589 | 617 |
590 void RenderWidgetHostViewViews::WillLoseFocus() { | 618 void RenderWidgetHostViewViews::WillLoseFocus() { |
591 // If we are showing a context menu, maintain the illusion that webkit has | 619 // If we are showing a context menu, maintain the illusion that webkit has |
592 // focus. | 620 // focus. |
593 if (!is_showing_context_menu_ && !is_hidden_) | 621 if (!is_showing_context_menu_ && !is_hidden_ && GetRenderWidgetHost()) |
agl
2011/02/07 17:26:47
This seems like it doesn't belong. If it's fixing
sadrul
2011/02/07 18:22:38
Indeed. This is a fix for a bug, and sneaked into
| |
594 GetRenderWidgetHost()->Blur(); | 622 GetRenderWidgetHost()->Blur(); |
595 } | 623 } |
596 | 624 |
597 | 625 |
598 void RenderWidgetHostViewViews::ShowCurrentCursor() { | 626 void RenderWidgetHostViewViews::ShowCurrentCursor() { |
599 // The widget may not have a window. If that's the case, abort mission. This | 627 // The widget may not have a window. If that's the case, abort mission. This |
600 // is the same issue as that explained above in Paint(). | 628 // is the same issue as that explained above in Paint(). |
601 if (!GetInnerNativeView() || !GetInnerNativeView()->window) | 629 if (!GetInnerNativeView() || !GetInnerNativeView()->window) |
602 return; | 630 return; |
603 | 631 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 } | 796 } |
769 | 797 |
770 // static | 798 // static |
771 RenderWidgetHostView* | 799 RenderWidgetHostView* |
772 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 800 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
773 gfx::NativeView widget) { | 801 gfx::NativeView widget) { |
774 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 802 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
775 kRenderWidgetHostViewKey); | 803 kRenderWidgetHostViewKey); |
776 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 804 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
777 } | 805 } |
OLD | NEW |