| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
| 18 #include "content/browser/renderer_host/backing_store_skia.h" | 18 #include "content/browser/renderer_host/backing_store_skia.h" |
| 19 #include "content/browser/renderer_host/render_widget_host.h" | 19 #include "content/browser/renderer_host/render_widget_host.h" |
| 20 #include "content/common/native_web_keyboard_event.h" | 20 #include "content/common/native_web_keyboard_event.h" |
| 21 #include "content/common/result_codes.h" | 21 #include "content/common/result_codes.h" |
| 22 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" |
| 25 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" | |
| 26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/x/x11_util.h" | |
| 28 #include "ui/gfx/canvas.h" | 26 #include "ui/gfx/canvas.h" |
| 29 #include "ui/gfx/canvas_skia.h" | 27 #include "ui/gfx/canvas_skia.h" |
| 30 #include "ui/gfx/gtk_native_view_id_manager.h" | |
| 31 #include "views/events/event.h" | 28 #include "views/events/event.h" |
| 32 #include "views/ime/input_method.h" | 29 #include "views/ime/input_method.h" |
| 33 #include "views/widget/native_widget_gtk.h" | |
| 34 #include "views/widget/widget.h" | 30 #include "views/widget/widget.h" |
| 35 | 31 |
| 36 static const int kMaxWindowWidth = 4000; | 32 static const int kMaxWindowWidth = 4000; |
| 37 static const int kMaxWindowHeight = 4000; | 33 static const int kMaxWindowHeight = 4000; |
| 38 static const char kRenderWidgetHostViewKey[] = "__RENDER_WIDGET_HOST_VIEW__"; | |
| 39 | 34 |
| 40 // Copied from third_party/WebKit/Source/WebCore/page/EventHandler.cpp | 35 // static |
| 41 // | 36 const char RenderWidgetHostViewViews::kViewClassName[] = |
| 42 // Match key code of composition keydown event on windows. | 37 "browser/renderer_host/RenderWidgetHostViewViews"; |
| 43 // IE sends VK_PROCESSKEY which has value 229; | |
| 44 // | |
| 45 // Please refer to following documents for detals: | |
| 46 // - Virtual-Key Codes | |
| 47 // http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx | |
| 48 // - How the IME System Works | |
| 49 // http://msdn.microsoft.com/en-us/library/cc194848.aspx | |
| 50 // - ImmGetVirtualKey Function | |
| 51 // http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx | |
| 52 static const int kCompositionEventKeyCode = 229; | |
| 53 | 38 |
| 54 using WebKit::WebInputEventFactory; | 39 using WebKit::WebInputEventFactory; |
| 55 using WebKit::WebMouseWheelEvent; | 40 using WebKit::WebMouseWheelEvent; |
| 56 using WebKit::WebTouchEvent; | 41 using WebKit::WebTouchEvent; |
| 57 | 42 |
| 58 const char RenderWidgetHostViewViews::kViewClassName[] = | |
| 59 "browser/renderer_host/RenderWidgetHostViewViews"; | |
| 60 | |
| 61 namespace { | 43 namespace { |
| 62 | 44 |
| 63 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { | 45 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { |
| 64 int modifiers = 0; | 46 int modifiers = 0; |
| 65 | 47 |
| 66 if (event.IsShiftDown()) | 48 if (event.IsShiftDown()) |
| 67 modifiers |= WebKit::WebInputEvent::ShiftKey; | 49 modifiers |= WebKit::WebInputEvent::ShiftKey; |
| 68 if (event.IsControlDown()) | 50 if (event.IsControlDown()) |
| 69 modifiers |= WebKit::WebInputEvent::ControlKey; | 51 modifiers |= WebKit::WebInputEvent::ControlKey; |
| 70 if (event.IsAltDown()) | 52 if (event.IsAltDown()) |
| 71 modifiers |= WebKit::WebInputEvent::AltKey; | 53 modifiers |= WebKit::WebInputEvent::AltKey; |
| 72 if (event.IsCapsLockDown()) | 54 if (event.IsCapsLockDown()) |
| 73 modifiers |= WebKit::WebInputEvent::CapsLockOn; | 55 modifiers |= WebKit::WebInputEvent::CapsLockOn; |
| 74 | 56 |
| 75 return modifiers; | 57 return modifiers; |
| 76 } | 58 } |
| 77 | 59 |
| 78 WebKit::WebTouchPoint::State TouchPointStateFromEvent( | |
| 79 const views::TouchEvent* event) { | |
| 80 switch (event->type()) { | |
| 81 case ui::ET_TOUCH_PRESSED: | |
| 82 return WebKit::WebTouchPoint::StatePressed; | |
| 83 case ui::ET_TOUCH_RELEASED: | |
| 84 return WebKit::WebTouchPoint::StateReleased; | |
| 85 case ui::ET_TOUCH_MOVED: | |
| 86 return WebKit::WebTouchPoint::StateMoved; | |
| 87 case ui::ET_TOUCH_CANCELLED: | |
| 88 return WebKit::WebTouchPoint::StateCancelled; | |
| 89 default: | |
| 90 return WebKit::WebTouchPoint::StateUndefined; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 WebKit::WebInputEvent::Type TouchEventTypeFromEvent( | |
| 95 const views::TouchEvent* event) { | |
| 96 switch (event->type()) { | |
| 97 case ui::ET_TOUCH_PRESSED: | |
| 98 return WebKit::WebInputEvent::TouchStart; | |
| 99 case ui::ET_TOUCH_RELEASED: | |
| 100 return WebKit::WebInputEvent::TouchEnd; | |
| 101 case ui::ET_TOUCH_MOVED: | |
| 102 return WebKit::WebInputEvent::TouchMove; | |
| 103 case ui::ET_TOUCH_CANCELLED: | |
| 104 return WebKit::WebInputEvent::TouchCancel; | |
| 105 default: | |
| 106 return WebKit::WebInputEvent::Undefined; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 inline void UpdateTouchParams(const views::TouchEvent& event, | |
| 111 WebKit::WebTouchPoint* tpoint) { | |
| 112 tpoint->radiusX = event.radius_x(); | |
| 113 tpoint->radiusY = event.radius_y(); | |
| 114 tpoint->rotationAngle = event.rotation_angle(); | |
| 115 tpoint->force = event.force(); | |
| 116 } | |
| 117 | |
| 118 void UpdateTouchPointPosition(const views::TouchEvent* event, | |
| 119 const gfx::Point& origin, | |
| 120 WebKit::WebTouchPoint* tpoint) { | |
| 121 tpoint->position.x = event->x(); | |
| 122 tpoint->position.y = event->y(); | |
| 123 | |
| 124 tpoint->screenPosition.x = tpoint->position.x + origin.x(); | |
| 125 tpoint->screenPosition.y = tpoint->position.y + origin.y(); | |
| 126 } | |
| 127 | |
| 128 void InitializeWebMouseEventFromViewsEvent(const views::LocatedEvent& event, | 60 void InitializeWebMouseEventFromViewsEvent(const views::LocatedEvent& event, |
| 129 const gfx::Point& origin, | 61 const gfx::Point& origin, |
| 130 WebKit::WebMouseEvent* wmevent) { | 62 WebKit::WebMouseEvent* wmevent) { |
| 131 wmevent->timeStampSeconds = base::Time::Now().ToDoubleT(); | 63 wmevent->timeStampSeconds = base::Time::Now().ToDoubleT(); |
| 132 wmevent->modifiers = WebInputEventFlagsFromViewsEvent(event); | 64 wmevent->modifiers = WebInputEventFlagsFromViewsEvent(event); |
| 133 | 65 |
| 134 wmevent->windowX = wmevent->x = event.x(); | 66 wmevent->windowX = wmevent->x = event.x(); |
| 135 wmevent->windowY = wmevent->y = event.y(); | 67 wmevent->windowY = wmevent->y = event.y(); |
| 136 wmevent->globalX = wmevent->x + origin.x(); | 68 wmevent->globalX = wmevent->x + origin.x(); |
| 137 wmevent->globalY = wmevent->y + origin.y(); | 69 wmevent->globalY = wmevent->y + origin.y(); |
| 138 } | 70 } |
| 139 | 71 |
| 140 } // namespace | 72 } // namespace |
| 141 | 73 |
| 142 // static | |
| 143 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | |
| 144 RenderWidgetHost* widget) { | |
| 145 return new RenderWidgetHostViewViews(widget); | |
| 146 } | |
| 147 | |
| 148 RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) | 74 RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) |
| 149 : host_(host), | 75 : host_(host), |
| 150 about_to_validate_and_paint_(false), | 76 about_to_validate_and_paint_(false), |
| 151 is_hidden_(false), | 77 is_hidden_(false), |
| 152 is_loading_(false), | 78 is_loading_(false), |
| 153 native_cursor_(NULL), | 79 native_cursor_(NULL), |
| 154 is_showing_popup_menu_(false), | 80 is_showing_popup_menu_(false), |
| 155 visually_deemphasized_(false), | 81 visually_deemphasized_(false), |
| 156 touch_event_(), | 82 touch_event_(), |
| 157 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 83 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 195 } |
| 270 | 196 |
| 271 bool RenderWidgetHostViewViews::IsShowing() { | 197 bool RenderWidgetHostViewViews::IsShowing() { |
| 272 return IsVisible(); | 198 return IsVisible(); |
| 273 } | 199 } |
| 274 | 200 |
| 275 gfx::Rect RenderWidgetHostViewViews::GetViewBounds() const { | 201 gfx::Rect RenderWidgetHostViewViews::GetViewBounds() const { |
| 276 return bounds(); | 202 return bounds(); |
| 277 } | 203 } |
| 278 | 204 |
| 279 void RenderWidgetHostViewViews::UpdateCursor(const WebCursor& cursor) { | |
| 280 // Optimize the common case, where the cursor hasn't changed. | |
| 281 // However, we can switch between different pixmaps, so only on the | |
| 282 // non-pixmap branch. | |
| 283 if (current_cursor_.GetCursorType() != GDK_CURSOR_IS_PIXMAP && | |
| 284 current_cursor_.GetCursorType() == cursor.GetCursorType()) { | |
| 285 return; | |
| 286 } | |
| 287 | |
| 288 current_cursor_ = cursor; | |
| 289 ShowCurrentCursor(); | |
| 290 } | |
| 291 | |
| 292 void RenderWidgetHostViewViews::SetIsLoading(bool is_loading) { | 205 void RenderWidgetHostViewViews::SetIsLoading(bool is_loading) { |
| 293 is_loading_ = is_loading; | 206 is_loading_ = is_loading; |
| 207 #if defined(TOOLKIT_USES_GTK) |
| 294 // Only call ShowCurrentCursor() when it will actually change the cursor. | 208 // Only call ShowCurrentCursor() when it will actually change the cursor. |
| 295 if (current_cursor_.GetCursorType() == GDK_LAST_CURSOR) | 209 if (current_cursor_.GetCursorType() == GDK_LAST_CURSOR) |
| 296 ShowCurrentCursor(); | 210 ShowCurrentCursor(); |
| 211 #endif // TOOLKIT_USES_GTK |
| 297 } | 212 } |
| 298 | 213 |
| 299 void RenderWidgetHostViewViews::ImeUpdateTextInputState( | 214 void RenderWidgetHostViewViews::ImeUpdateTextInputState( |
| 300 ui::TextInputType type, | 215 ui::TextInputType type, |
| 301 bool can_compose_inline, | 216 bool can_compose_inline, |
| 302 const gfx::Rect& caret_rect) { | 217 const gfx::Rect& caret_rect) { |
| 303 // TODO(kinaba): currently, can_compose_inline is ignored and always treated | 218 // TODO(kinaba): currently, can_compose_inline is ignored and always treated |
| 304 // as true. We need to support "can_compose_inline=false" for PPAPI plugins | 219 // as true. We need to support "can_compose_inline=false" for PPAPI plugins |
| 305 // that may want to avoid drawing composition-text by themselves and pass | 220 // that may want to avoid drawing composition-text by themselves and pass |
| 306 // the responsibility to the browser. | 221 // the responsibility to the browser. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 312 |
| 398 return new BackingStoreSkia(host_, size); | 313 return new BackingStoreSkia(host_, size); |
| 399 } | 314 } |
| 400 | 315 |
| 401 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { | 316 void RenderWidgetHostViewViews::SetBackground(const SkBitmap& background) { |
| 402 RenderWidgetHostView::SetBackground(background); | 317 RenderWidgetHostView::SetBackground(background); |
| 403 if (host_) | 318 if (host_) |
| 404 host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); | 319 host_->Send(new ViewMsg_SetBackground(host_->routing_id(), background)); |
| 405 } | 320 } |
| 406 | 321 |
| 407 void RenderWidgetHostViewViews::CreatePluginContainer( | |
| 408 gfx::PluginWindowHandle id) { | |
| 409 // TODO(anicolao): plugin_container_manager_.CreatePluginContainer(id); | |
| 410 } | |
| 411 | |
| 412 void RenderWidgetHostViewViews::DestroyPluginContainer( | |
| 413 gfx::PluginWindowHandle id) { | |
| 414 // TODO(anicolao): plugin_container_manager_.DestroyPluginContainer(id); | |
| 415 } | |
| 416 | |
| 417 void RenderWidgetHostViewViews::SetVisuallyDeemphasized( | 322 void RenderWidgetHostViewViews::SetVisuallyDeemphasized( |
| 418 const SkColor* color, bool animate) { | 323 const SkColor* color, bool animate) { |
| 419 // TODO(anicolao) | 324 // TODO(anicolao) |
| 420 } | 325 } |
| 421 | 326 |
| 422 bool RenderWidgetHostViewViews::ContainsNativeView( | 327 bool RenderWidgetHostViewViews::ContainsNativeView( |
| 423 gfx::NativeView native_view) const { | 328 gfx::NativeView native_view) const { |
| 424 // TODO(port) | 329 // TODO(port) |
| 425 NOTREACHED() << | 330 NOTREACHED() << |
| 426 "RenderWidgetHostViewViews::ContainsNativeView not implemented."; | 331 "RenderWidgetHostViewViews::ContainsNativeView not implemented."; |
| 427 return false; | 332 return false; |
| 428 } | 333 } |
| 429 | 334 |
| 430 void RenderWidgetHostViewViews::AcceleratedCompositingActivated( | |
| 431 bool activated) { | |
| 432 // TODO(anicolao): figure out if we need something here | |
| 433 if (activated) | |
| 434 NOTIMPLEMENTED(); | |
| 435 } | |
| 436 | |
| 437 gfx::PluginWindowHandle RenderWidgetHostViewViews::GetCompositingSurface() { | |
| 438 GtkNativeViewManager* manager = GtkNativeViewManager::GetInstance(); | |
| 439 gfx::PluginWindowHandle surface = gfx::kNullPluginWindow; | |
| 440 gfx::NativeViewId view_id = gfx::IdFromNativeView(GetInnerNativeView()); | |
| 441 | |
| 442 if (!manager->GetXIDForId(&surface, view_id)) { | |
| 443 DLOG(ERROR) << "Can't find XID for view id " << view_id; | |
| 444 } | |
| 445 return surface; | |
| 446 } | |
| 447 | |
| 448 gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { | |
| 449 // TODO(sad): Ideally this function should be equivalent to GetNativeView, and | |
| 450 // NativeWidgetGtk-specific function call should not be necessary. | |
| 451 const views::Widget* widget = GetWidget(); | |
| 452 const views::NativeWidget* native = widget ? widget->native_widget() : NULL; | |
| 453 return native ? static_cast<const views::NativeWidgetGtk*>(native)-> | |
| 454 window_contents() : NULL; | |
| 455 } | |
| 456 | |
| 457 std::string RenderWidgetHostViewViews::GetClassName() const { | 335 std::string RenderWidgetHostViewViews::GetClassName() const { |
| 458 return kViewClassName; | 336 return kViewClassName; |
| 459 } | 337 } |
| 460 | 338 |
| 461 gfx::NativeCursor RenderWidgetHostViewViews::GetCursor( | 339 gfx::NativeCursor RenderWidgetHostViewViews::GetCursor( |
| 462 const views::MouseEvent& event) { | 340 const views::MouseEvent& event) { |
| 463 return native_cursor_; | 341 return native_cursor_; |
| 464 } | 342 } |
| 465 | 343 |
| 466 bool RenderWidgetHostViewViews::OnMousePressed(const views::MouseEvent& event) { | 344 bool RenderWidgetHostViewViews::OnMousePressed(const views::MouseEvent& event) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 } | 388 } |
| 511 | 389 |
| 512 void RenderWidgetHostViewViews::OnMouseEntered(const views::MouseEvent& event) { | 390 void RenderWidgetHostViewViews::OnMouseEntered(const views::MouseEvent& event) { |
| 513 // Already generated synthetically by webkit. | 391 // Already generated synthetically by webkit. |
| 514 } | 392 } |
| 515 | 393 |
| 516 void RenderWidgetHostViewViews::OnMouseExited(const views::MouseEvent& event) { | 394 void RenderWidgetHostViewViews::OnMouseExited(const views::MouseEvent& event) { |
| 517 // Already generated synthetically by webkit. | 395 // Already generated synthetically by webkit. |
| 518 } | 396 } |
| 519 | 397 |
| 520 ui::TouchStatus RenderWidgetHostViewViews::OnTouchEvent( | |
| 521 const views::TouchEvent& event) { | |
| 522 if (!host_) | |
| 523 return ui::TOUCH_STATUS_UNKNOWN; | |
| 524 | |
| 525 // Update the list of touch points first. | |
| 526 WebKit::WebTouchPoint* point = NULL; | |
| 527 ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; | |
| 528 | |
| 529 switch (event.type()) { | |
| 530 case ui::ET_TOUCH_PRESSED: | |
| 531 // Add a new touch point. | |
| 532 if (touch_event_.touchPointsLength < | |
| 533 WebTouchEvent::touchPointsLengthCap) { | |
| 534 point = &touch_event_.touchPoints[touch_event_.touchPointsLength++]; | |
| 535 point->id = event.identity(); | |
| 536 | |
| 537 if (touch_event_.touchPointsLength == 1) { | |
| 538 // A new touch sequence has started. | |
| 539 status = ui::TOUCH_STATUS_START; | |
| 540 | |
| 541 // We also want the focus. | |
| 542 RequestFocus(); | |
| 543 | |
| 544 // Confirm existing composition text on touch press events, to make | |
| 545 // sure the input caret won't be moved with an ongoing composition | |
| 546 // text. | |
| 547 FinishImeCompositionSession(); | |
| 548 } | |
| 549 } | |
| 550 break; | |
| 551 case ui::ET_TOUCH_RELEASED: | |
| 552 case ui::ET_TOUCH_CANCELLED: | |
| 553 case ui::ET_TOUCH_MOVED: { | |
| 554 // The touch point should have been added to the event from an earlier | |
| 555 // _PRESSED event. So find that. | |
| 556 // At the moment, only a maximum of 4 touch-points are allowed. So a | |
| 557 // simple loop should be sufficient. | |
| 558 for (int i = 0; i < touch_event_.touchPointsLength; ++i) { | |
| 559 point = touch_event_.touchPoints + i; | |
| 560 if (point->id == event.identity()) { | |
| 561 break; | |
| 562 } | |
| 563 point = NULL; | |
| 564 } | |
| 565 break; | |
| 566 } | |
| 567 default: | |
| 568 DLOG(WARNING) << "Unknown touch event " << event.type(); | |
| 569 break; | |
| 570 } | |
| 571 | |
| 572 if (!point) | |
| 573 return ui::TOUCH_STATUS_UNKNOWN; | |
| 574 | |
| 575 if (status != ui::TOUCH_STATUS_START) | |
| 576 status = ui::TOUCH_STATUS_CONTINUE; | |
| 577 | |
| 578 UpdateTouchParams(event, point); | |
| 579 | |
| 580 // Update the location and state of the point. | |
| 581 point->state = TouchPointStateFromEvent(&event); | |
| 582 if (point->state == WebKit::WebTouchPoint::StateMoved) { | |
| 583 // It is possible for badly written touch drivers to emit Move events even | |
| 584 // when the touch location hasn't changed. In such cases, consume the event | |
| 585 // and pretend nothing happened. | |
| 586 if (point->position.x == event.x() && point->position.y == event.y()) { | |
| 587 return status; | |
| 588 } | |
| 589 } | |
| 590 UpdateTouchPointPosition(&event, GetMirroredPosition(), point); | |
| 591 | |
| 592 // Mark the rest of the points as stationary. | |
| 593 for (int i = 0; i < touch_event_.touchPointsLength; ++i) { | |
| 594 WebKit::WebTouchPoint* iter = touch_event_.touchPoints + i; | |
| 595 if (iter != point) { | |
| 596 iter->state = WebKit::WebTouchPoint::StateStationary; | |
| 597 } | |
| 598 } | |
| 599 | |
| 600 // Update the type of the touch event. | |
| 601 touch_event_.type = TouchEventTypeFromEvent(&event); | |
| 602 touch_event_.timeStampSeconds = base::Time::Now().ToDoubleT(); | |
| 603 | |
| 604 // The event and all the touches have been updated. Dispatch. | |
| 605 host_->ForwardTouchEvent(touch_event_); | |
| 606 | |
| 607 // If the touch was released, then remove it from the list of touch points. | |
| 608 if (event.type() == ui::ET_TOUCH_RELEASED) { | |
| 609 --touch_event_.touchPointsLength; | |
| 610 for (int i = point - touch_event_.touchPoints; | |
| 611 i < touch_event_.touchPointsLength; | |
| 612 ++i) { | |
| 613 touch_event_.touchPoints[i] = touch_event_.touchPoints[i + 1]; | |
| 614 } | |
| 615 if (touch_event_.touchPointsLength == 0) | |
| 616 status = ui::TOUCH_STATUS_END; | |
| 617 } else if (event.type() == ui::ET_TOUCH_CANCELLED) { | |
| 618 status = ui::TOUCH_STATUS_CANCEL; | |
| 619 } | |
| 620 | |
| 621 return status; | |
| 622 } | |
| 623 | |
| 624 bool RenderWidgetHostViewViews::OnKeyPressed(const views::KeyEvent& event) { | 398 bool RenderWidgetHostViewViews::OnKeyPressed(const views::KeyEvent& event) { |
| 625 // TODO(suzhe): Support editor key bindings. | 399 // TODO(suzhe): Support editor key bindings. |
| 626 if (!host_) | 400 if (!host_) |
| 627 return false; | 401 return false; |
| 628 host_->ForwardKeyboardEvent(NativeWebKeyboardEvent(event)); | 402 host_->ForwardKeyboardEvent(NativeWebKeyboardEvent(event)); |
| 629 return true; | 403 return true; |
| 630 } | 404 } |
| 631 | 405 |
| 632 bool RenderWidgetHostViewViews::OnKeyReleased(const views::KeyEvent& event) { | 406 bool RenderWidgetHostViewViews::OnKeyReleased(const views::KeyEvent& event) { |
| 633 if (!host_) | 407 if (!host_) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 // Later views might still get to paint on top. | 574 // Later views might still get to paint on top. |
| 801 canvas->FillRectInt(SK_ColorBLACK, 0, 0, | 575 canvas->FillRectInt(SK_ColorBLACK, 0, 0, |
| 802 bounds().width(), bounds().height(), | 576 bounds().width(), bounds().height(), |
| 803 SkXfermode::kClear_Mode); | 577 SkXfermode::kClear_Mode); |
| 804 | 578 |
| 805 // Don't do any painting if the GPU process is rendering directly | 579 // Don't do any painting if the GPU process is rendering directly |
| 806 // into the View. | 580 // into the View. |
| 807 if (host_->is_accelerated_compositing_active()) | 581 if (host_->is_accelerated_compositing_active()) |
| 808 return; | 582 return; |
| 809 | 583 |
| 584 #if defined(TOOLKIT_USES_GTK) |
| 810 GdkWindow* window = GetInnerNativeView()->window; | 585 GdkWindow* window = GetInnerNativeView()->window; |
| 586 #endif |
| 811 DCHECK(!about_to_validate_and_paint_); | 587 DCHECK(!about_to_validate_and_paint_); |
| 812 | 588 |
| 813 // TODO(anicolao): get the damage somehow | 589 // TODO(anicolao): get the damage somehow |
| 814 // invalid_rect_ = damage_rect; | 590 // invalid_rect_ = damage_rect; |
| 815 invalid_rect_ = bounds(); | 591 invalid_rect_ = bounds(); |
| 816 gfx::Point origin; | 592 gfx::Point origin; |
| 817 ConvertPointToWidget(this, &origin); | 593 ConvertPointToWidget(this, &origin); |
| 818 | 594 |
| 819 about_to_validate_and_paint_ = true; | 595 about_to_validate_and_paint_ = true; |
| 820 BackingStore* backing_store = host_->GetBackingStore(true); | 596 BackingStore* backing_store = host_->GetBackingStore(true); |
| 821 // Calling GetBackingStore maybe have changed |invalid_rect_|... | 597 // Calling GetBackingStore maybe have changed |invalid_rect_|... |
| 822 about_to_validate_and_paint_ = false; | 598 about_to_validate_and_paint_ = false; |
| 823 | 599 |
| 824 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); | 600 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); |
| 825 paint_rect = paint_rect.Intersect(invalid_rect_); | 601 paint_rect = paint_rect.Intersect(invalid_rect_); |
| 826 | 602 |
| 827 if (backing_store) { | 603 if (backing_store) { |
| 604 #if defined(TOOLKIT_USES_GTK) |
| 828 // Only render the widget if it is attached to a window; there's a short | 605 // Only render the widget if it is attached to a window; there's a short |
| 829 // period where this object isn't attached to a window but hasn't been | 606 // period where this object isn't attached to a window but hasn't been |
| 830 // Destroy()ed yet and it receives paint messages... | 607 // Destroy()ed yet and it receives paint messages... |
| 831 if (window) { | 608 if (window) { |
| 609 #endif |
| 832 if (!visually_deemphasized_) { | 610 if (!visually_deemphasized_) { |
| 833 // In the common case, use XCopyArea. We don't draw more than once, so | 611 // In the common case, use XCopyArea. We don't draw more than once, so |
| 834 // we don't need to double buffer. | 612 // we don't need to double buffer. |
| 835 if (IsPopup()) { | 613 if (IsPopup()) { |
| 836 origin.SetPoint(origin.x() + paint_rect.x(), | 614 origin.SetPoint(origin.x() + paint_rect.x(), |
| 837 origin.y() + paint_rect.y()); | 615 origin.y() + paint_rect.y()); |
| 838 paint_rect.SetRect(0, 0, paint_rect.width(), paint_rect.height()); | 616 paint_rect.SetRect(0, 0, paint_rect.width(), paint_rect.height()); |
| 839 } | 617 } |
| 840 static_cast<BackingStoreSkia*>(backing_store)->SkiaShowRect( | 618 static_cast<BackingStoreSkia*>(backing_store)->SkiaShowRect( |
| 841 gfx::Point(paint_rect.x(), paint_rect.y()), canvas); | 619 gfx::Point(paint_rect.x(), paint_rect.y()), canvas); |
| 842 } else { | 620 } else { |
| 843 // TODO(sad) | 621 // TODO(sad) |
| 844 NOTIMPLEMENTED(); | 622 NOTIMPLEMENTED(); |
| 845 } | 623 } |
| 624 #if defined(TOOLKIT_USES_GTK) |
| 846 } | 625 } |
| 626 #endif |
| 847 if (!whiteout_start_time_.is_null()) { | 627 if (!whiteout_start_time_.is_null()) { |
| 848 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - | 628 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - |
| 849 whiteout_start_time_; | 629 whiteout_start_time_; |
| 850 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); | 630 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); |
| 851 | 631 |
| 852 // Reset the start time to 0 so that we start recording again the next | 632 // Reset the start time to 0 so that we start recording again the next |
| 853 // time the backing store is NULL... | 633 // time the backing store is NULL... |
| 854 whiteout_start_time_ = base::TimeTicks(); | 634 whiteout_start_time_ = base::TimeTicks(); |
| 855 } | 635 } |
| 856 if (!tab_switch_paint_time_.is_null()) { | 636 if (!tab_switch_paint_time_.is_null()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 } | 682 } |
| 903 | 683 |
| 904 bool RenderWidgetHostViewViews::NeedsInputGrab() { | 684 bool RenderWidgetHostViewViews::NeedsInputGrab() { |
| 905 return popup_type_ == WebKit::WebPopupTypeSelect; | 685 return popup_type_ == WebKit::WebPopupTypeSelect; |
| 906 } | 686 } |
| 907 | 687 |
| 908 bool RenderWidgetHostViewViews::IsPopup() { | 688 bool RenderWidgetHostViewViews::IsPopup() { |
| 909 return popup_type_ != WebKit::WebPopupTypeNone; | 689 return popup_type_ != WebKit::WebPopupTypeNone; |
| 910 } | 690 } |
| 911 | 691 |
| 912 void RenderWidgetHostViewViews::ShowCurrentCursor() { | |
| 913 // The widget may not have a window. If that's the case, abort mission. This | |
| 914 // is the same issue as that explained above in Paint(). | |
| 915 if (!GetInnerNativeView() || !GetInnerNativeView()->window) | |
| 916 return; | |
| 917 | |
| 918 native_cursor_ = current_cursor_.GetNativeCursor(); | |
| 919 } | |
| 920 | |
| 921 WebKit::WebMouseEvent RenderWidgetHostViewViews::WebMouseEventFromViewsEvent( | 692 WebKit::WebMouseEvent RenderWidgetHostViewViews::WebMouseEventFromViewsEvent( |
| 922 const views::MouseEvent& event) { | 693 const views::MouseEvent& event) { |
| 923 WebKit::WebMouseEvent wmevent; | 694 WebKit::WebMouseEvent wmevent; |
| 924 InitializeWebMouseEventFromViewsEvent(event, GetMirroredPosition(), &wmevent); | 695 InitializeWebMouseEventFromViewsEvent(event, GetMirroredPosition(), &wmevent); |
| 925 | 696 |
| 926 // Setting |wmevent.button| is not necessary for -move events, but it is | 697 // Setting |wmevent.button| is not necessary for -move events, but it is |
| 927 // necessary for -clicks and -drags. | 698 // necessary for -clicks and -drags. |
| 928 if (event.IsMiddleMouseButton()) { | 699 if (event.IsMiddleMouseButton()) { |
| 929 wmevent.modifiers |= WebKit::WebInputEvent::MiddleButtonDown; | 700 wmevent.modifiers |= WebKit::WebInputEvent::MiddleButtonDown; |
| 930 wmevent.button = WebKit::WebMouseEvent::ButtonMiddle; | 701 wmevent.button = WebKit::WebMouseEvent::ButtonMiddle; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 943 | 714 |
| 944 void RenderWidgetHostViewViews::FinishImeCompositionSession() { | 715 void RenderWidgetHostViewViews::FinishImeCompositionSession() { |
| 945 if (!has_composition_text_) | 716 if (!has_composition_text_) |
| 946 return; | 717 return; |
| 947 if (host_) | 718 if (host_) |
| 948 host_->ImeConfirmComposition(); | 719 host_->ImeConfirmComposition(); |
| 949 DCHECK(GetInputMethod()); | 720 DCHECK(GetInputMethod()); |
| 950 GetInputMethod()->CancelComposition(this); | 721 GetInputMethod()->CancelComposition(this); |
| 951 has_composition_text_ = false; | 722 has_composition_text_ = false; |
| 952 } | 723 } |
| 953 | |
| 954 // static | |
| 955 RenderWidgetHostView* | |
| 956 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | |
| 957 gfx::NativeView widget) { | |
| 958 gpointer user_data = g_object_get_data(G_OBJECT(widget), | |
| 959 kRenderWidgetHostViewKey); | |
| 960 return reinterpret_cast<RenderWidgetHostView*>(user_data); | |
| 961 } | |
| OLD | NEW |