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_x.h" | 17 #include "chrome/browser/renderer_host/backing_store_x.h" |
18 #include "chrome/browser/renderer_host/render_widget_host.h" | 18 #include "chrome/browser/renderer_host/render_widget_host.h" |
19 #include "chrome/common/native_web_keyboard_event.h" | 19 #include "chrome/common/native_web_keyboard_event.h" |
20 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
21 #include "chrome/common/result_codes.h" | 21 #include "chrome/common/result_codes.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.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 "ui/base/keycodes/keyboard_code_conversion_gtk.h" | 24 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/base/x/x11_util.h" | 26 #include "ui/base/x/x11_util.h" |
27 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
28 #include "views/events/event.h" | 28 #include "views/events/event.h" |
| 29 #include "views/ime/ime_context.h" |
29 #include "views/widget/widget.h" | 30 #include "views/widget/widget.h" |
30 #include "views/widget/widget_gtk.h" | 31 #include "views/widget/widget_gtk.h" |
31 | 32 |
32 static const int kMaxWindowWidth = 4000; | 33 static const int kMaxWindowWidth = 4000; |
33 static const int kMaxWindowHeight = 4000; | 34 static const int kMaxWindowHeight = 4000; |
34 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 35 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; |
35 | 36 |
| 37 // Copied from third_party/WebKit/Source/WebCore/page/EventHandler.cpp |
| 38 // |
| 39 // Match key code of composition keydown event on windows. |
| 40 // IE sends VK_PROCESSKEY which has value 229; |
| 41 // |
| 42 // Please refer to following documents for detals: |
| 43 // - Virtual-Key Codes |
| 44 // http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx |
| 45 // - How the IME System Works |
| 46 // http://msdn.microsoft.com/en-us/library/cc194848.aspx |
| 47 // - ImmGetVirtualKey Function |
| 48 // http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx |
| 49 static const int kCompositionEventKeyCode = 229; |
| 50 |
36 using WebKit::WebInputEventFactory; | 51 using WebKit::WebInputEventFactory; |
37 using WebKit::WebMouseWheelEvent; | 52 using WebKit::WebMouseWheelEvent; |
38 using WebKit::WebTouchEvent; | 53 using WebKit::WebTouchEvent; |
39 | 54 |
40 const char RenderWidgetHostViewViews::kViewClassName[] = | 55 const char RenderWidgetHostViewViews::kViewClassName[] = |
41 "browser/renderer_host/RenderWidgetHostViewViews"; | 56 "browser/renderer_host/RenderWidgetHostViewViews"; |
42 | 57 |
43 namespace { | 58 namespace { |
44 | 59 |
45 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { | 60 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 wmevent->modifiers = WebInputEventFlagsFromViewsEvent(e); | 121 wmevent->modifiers = WebInputEventFlagsFromViewsEvent(e); |
107 | 122 |
108 wmevent->windowX = wmevent->x = e.x(); | 123 wmevent->windowX = wmevent->x = e.x(); |
109 wmevent->windowY = wmevent->y = e.y(); | 124 wmevent->windowY = wmevent->y = e.y(); |
110 wmevent->globalX = wmevent->x + origin.x(); | 125 wmevent->globalX = wmevent->x + origin.x(); |
111 wmevent->globalY = wmevent->y + origin.y(); | 126 wmevent->globalY = wmevent->y + origin.y(); |
112 } | 127 } |
113 | 128 |
114 } // namespace | 129 } // namespace |
115 | 130 |
| 131 class IMEContextHandler : public views::CommitTextListener, |
| 132 public views::CompositionListener, |
| 133 public views::ForwardKeyEventListener { |
| 134 public: |
| 135 explicit IMEContextHandler( |
| 136 RenderWidgetHostViewViews* host_view) |
| 137 : host_view_(host_view), |
| 138 is_enabled_(false), |
| 139 is_focused_(false), |
| 140 ime_context_(views::IMEContext::Create(host_view_)) { |
| 141 ime_context_->set_commit_text_listener(this); |
| 142 ime_context_->set_composition_listener(this); |
| 143 ime_context_->set_forward_key_event_listener(this); |
| 144 } |
| 145 |
| 146 // IMEContext Listeners implementation |
| 147 virtual void OnCommitText(views::IMEContext* sender, |
| 148 const string16& text) { |
| 149 DCHECK(ime_context_ == sender); |
| 150 |
| 151 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); |
| 152 if (host) { |
| 153 SendFakeCompositionWebKeyboardEvent(WebKit::WebInputEvent::RawKeyDown); |
| 154 host->ImeConfirmComposition(text); |
| 155 SendFakeCompositionWebKeyboardEvent(WebKit::WebInputEvent::KeyUp); |
| 156 } |
| 157 } |
| 158 |
| 159 virtual void OnStartComposition(views::IMEContext* sender) { |
| 160 DCHECK(ime_context_ == sender); |
| 161 } |
| 162 |
| 163 virtual void OnEndComposition(views::IMEContext* sender) { |
| 164 DCHECK(ime_context_ == sender); |
| 165 |
| 166 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); |
| 167 if (host) |
| 168 host->ImeCancelComposition(); |
| 169 } |
| 170 |
| 171 virtual void OnSetComposition(views::IMEContext* sender, |
| 172 const string16& text, |
| 173 const views::CompositionAttributeList& attributes, |
| 174 uint32 cursor_pos) { |
| 175 DCHECK(ime_context_ == sender); |
| 176 |
| 177 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); |
| 178 if (host) { |
| 179 SendFakeCompositionWebKeyboardEvent(WebKit::WebInputEvent::RawKeyDown); |
| 180 |
| 181 // Cast CompositonAttribute to WebKit::WebCompositionUnderline directly, |
| 182 // becasue CompositionAttribute is duplicated from |
| 183 // WebKit::WebCompositionUnderline. |
| 184 const std::vector<WebKit::WebCompositionUnderline>& underlines = |
| 185 reinterpret_cast<const std::vector<WebKit::WebCompositionUnderline>&>( |
| 186 attributes); |
| 187 host->ImeSetComposition(text, underlines, cursor_pos, cursor_pos); |
| 188 SendFakeCompositionWebKeyboardEvent(WebKit::WebInputEvent::KeyUp); |
| 189 } |
| 190 } |
| 191 |
| 192 virtual void OnForwardKeyEvent(views::IMEContext* sender, |
| 193 const views::KeyEvent& event) { |
| 194 DCHECK(ime_context_ == sender); |
| 195 |
| 196 host_view_->ForwardKeyEvent(event); |
| 197 } |
| 198 |
| 199 bool FilterKeyEvent(const views::KeyEvent& event) { |
| 200 return is_enabled_ && ime_context_->FilterKeyEvent(event); |
| 201 } |
| 202 |
| 203 void Focus() { |
| 204 if (!is_focused_) { |
| 205 ime_context_->Focus(); |
| 206 is_focused_ = true; |
| 207 } |
| 208 |
| 209 // Enables RenderWidget's IME related events, so that we can be notified |
| 210 // when WebKit wants to enable or disable IME. |
| 211 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); |
| 212 if (host) |
| 213 host->SetInputMethodActive(true); |
| 214 } |
| 215 |
| 216 void Blur() { |
| 217 if (is_focused_) { |
| 218 ime_context_->Blur(); |
| 219 is_focused_ = false; |
| 220 } |
| 221 |
| 222 // Disable RenderWidget's IME related events to save bandwidth. |
| 223 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); |
| 224 if (host) |
| 225 host->SetInputMethodActive(false); |
| 226 } |
| 227 |
| 228 void ImeUpdateTextInputState(WebKit::WebTextInputType type, |
| 229 const gfx::Rect& caret_rect) { |
| 230 bool enable = |
| 231 (type != WebKit::WebTextInputTypeNone) && |
| 232 (type != WebKit::WebTextInputTypePassword); |
| 233 |
| 234 if (is_enabled_ != enable) { |
| 235 is_enabled_ = enable; |
| 236 if (is_focused_) { |
| 237 if (is_enabled_) |
| 238 ime_context_->Focus(); |
| 239 else |
| 240 ime_context_->Blur(); |
| 241 } |
| 242 } |
| 243 |
| 244 if (is_enabled_) { |
| 245 gfx::Point p(caret_rect.origin()); |
| 246 views::View::ConvertPointToScreen(host_view_, &p); |
| 247 |
| 248 ime_context_->SetCursorLocation(gfx::Rect(p, caret_rect.size())); |
| 249 } |
| 250 } |
| 251 |
| 252 void Reset() { |
| 253 ime_context_->Reset(); |
| 254 } |
| 255 |
| 256 private: |
| 257 void SendFakeCompositionWebKeyboardEvent(WebKit::WebInputEvent::Type type) { |
| 258 NativeWebKeyboardEvent fake_event; |
| 259 fake_event.windowsKeyCode = kCompositionEventKeyCode; |
| 260 fake_event.skip_in_browser = true; |
| 261 fake_event.type = type; |
| 262 host_view_->ForwardWebKeyboardEvent(fake_event); |
| 263 } |
| 264 |
| 265 private: |
| 266 RenderWidgetHostViewViews* host_view_; |
| 267 bool is_enabled_; |
| 268 bool is_focused_; |
| 269 scoped_ptr<views::IMEContext> ime_context_; |
| 270 |
| 271 DISALLOW_COPY_AND_ASSIGN(IMEContextHandler); |
| 272 }; |
| 273 |
116 // static | 274 // static |
117 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 275 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
118 RenderWidgetHost* widget) { | 276 RenderWidgetHost* widget) { |
119 return new RenderWidgetHostViewViews(widget); | 277 return new RenderWidgetHostViewViews(widget); |
120 } | 278 } |
121 | 279 |
122 RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) | 280 RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) |
123 : host_(host), | 281 : host_(host), |
124 about_to_validate_and_paint_(false), | 282 about_to_validate_and_paint_(false), |
125 is_hidden_(false), | 283 is_hidden_(false), |
126 is_loading_(false), | 284 is_loading_(false), |
127 native_cursor_(NULL), | 285 native_cursor_(NULL), |
128 is_showing_context_menu_(false), | 286 is_showing_context_menu_(false), |
129 visually_deemphasized_(false), | 287 visually_deemphasized_(false), |
130 touch_event_() { | 288 touch_event_() { |
131 SetFocusable(true); | 289 SetFocusable(true); |
132 host_->set_view(this); | 290 host_->set_view(this); |
133 } | 291 } |
134 | 292 |
135 RenderWidgetHostViewViews::~RenderWidgetHostViewViews() { | 293 RenderWidgetHostViewViews::~RenderWidgetHostViewViews() { |
136 } | 294 } |
137 | 295 |
138 void RenderWidgetHostViewViews::InitAsChild() { | 296 void RenderWidgetHostViewViews::InitAsChild() { |
139 Show(); | 297 Show(); |
| 298 ime_context_.reset(new IMEContextHandler(this)); |
140 } | 299 } |
141 | 300 |
142 RenderWidgetHost* RenderWidgetHostViewViews::GetRenderWidgetHost() const { | 301 RenderWidgetHost* RenderWidgetHostViewViews::GetRenderWidgetHost() const { |
143 return host_; | 302 return host_; |
144 } | 303 } |
145 | 304 |
146 void RenderWidgetHostViewViews::InitAsPopup( | 305 void RenderWidgetHostViewViews::InitAsPopup( |
147 RenderWidgetHostView* parent_host_view, | 306 RenderWidgetHostView* parent_host_view, |
148 const gfx::Rect& pos) { | 307 const gfx::Rect& pos) { |
149 // TODO(anicolao): figure out cases where popups occur and implement | 308 // TODO(anicolao): figure out cases where popups occur and implement |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 void RenderWidgetHostViewViews::SetIsLoading(bool is_loading) { | 401 void RenderWidgetHostViewViews::SetIsLoading(bool is_loading) { |
243 is_loading_ = is_loading; | 402 is_loading_ = is_loading; |
244 // Only call ShowCurrentCursor() when it will actually change the cursor. | 403 // Only call ShowCurrentCursor() when it will actually change the cursor. |
245 if (current_cursor_.GetCursorType() == GDK_LAST_CURSOR) | 404 if (current_cursor_.GetCursorType() == GDK_LAST_CURSOR) |
246 ShowCurrentCursor(); | 405 ShowCurrentCursor(); |
247 } | 406 } |
248 | 407 |
249 void RenderWidgetHostViewViews::ImeUpdateTextInputState( | 408 void RenderWidgetHostViewViews::ImeUpdateTextInputState( |
250 WebKit::WebTextInputType type, | 409 WebKit::WebTextInputType type, |
251 const gfx::Rect& caret_rect) { | 410 const gfx::Rect& caret_rect) { |
252 // TODO(bryeung): im_context_->UpdateInputMethodState(type, caret_rect); | 411 ime_context_->ImeUpdateTextInputState(type, caret_rect); |
253 NOTIMPLEMENTED(); | |
254 } | 412 } |
255 | 413 |
256 void RenderWidgetHostViewViews::ImeCancelComposition() { | 414 void RenderWidgetHostViewViews::ImeCancelComposition() { |
257 // TODO(bryeung): im_context_->CancelComposition(); | 415 ime_context_->Reset(); |
258 NOTIMPLEMENTED(); | |
259 } | 416 } |
260 | 417 |
261 void RenderWidgetHostViewViews::DidUpdateBackingStore( | 418 void RenderWidgetHostViewViews::DidUpdateBackingStore( |
262 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, | 419 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, |
263 const std::vector<gfx::Rect>& copy_rects) { | 420 const std::vector<gfx::Rect>& copy_rects) { |
264 if (is_hidden_) | 421 if (is_hidden_) |
265 return; | 422 return; |
266 | 423 |
267 // TODO(darin): Implement the equivalent of Win32's ScrollWindowEX. Can that | 424 // TODO(darin): Implement the equivalent of Win32's ScrollWindowEX. Can that |
268 // be done using XCopyArea? Perhaps similar to | 425 // be done using XCopyArea? Perhaps similar to |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 wmwe.button = WebKit::WebMouseEvent::ButtonNone; | 659 wmwe.button = WebKit::WebMouseEvent::ButtonNone; |
503 | 660 |
504 // TODO(sadrul): How do we determine if it's a horizontal scroll? | 661 // TODO(sadrul): How do we determine if it's a horizontal scroll? |
505 wmwe.deltaY = e.offset(); | 662 wmwe.deltaY = e.offset(); |
506 wmwe.wheelTicksY = wmwe.deltaY > 0 ? 1 : -1; | 663 wmwe.wheelTicksY = wmwe.deltaY > 0 ? 1 : -1; |
507 | 664 |
508 GetRenderWidgetHost()->ForwardWheelEvent(wmwe); | 665 GetRenderWidgetHost()->ForwardWheelEvent(wmwe); |
509 return true; | 666 return true; |
510 } | 667 } |
511 | 668 |
512 bool RenderWidgetHostViewViews::OnKeyPressed(const views::KeyEvent &e) { | 669 bool RenderWidgetHostViewViews::OnKeyPressed(const views::KeyEvent& e) { |
513 // Send key event to input method. | 670 if (!ime_context_->FilterKeyEvent(e)) |
514 // TODO host_view->im_context_->ProcessKeyEvent(event); | 671 ForwardKeyEvent(e); |
515 | |
516 // This is how it works: | |
517 // (1) If a RawKeyDown event is an accelerator for a reserved command (see | |
518 // Browser::IsReservedCommand), then the command is executed. Otherwise, | |
519 // the event is first sent off to the renderer. The renderer is also | |
520 // notified whether the event would trigger an accelerator in the browser. | |
521 // (2) A Char event is then sent to the renderer. | |
522 // (3) If the renderer does not process the event in step (1), and the event | |
523 // triggers an accelerator, then it will ignore the event in step (2). The | |
524 // renderer also sends back notification to the browser for both steps (1) | |
525 // and (2) about whether the events were processed or not. If the event | |
526 // for (1) is not processed by the renderer, then it is processed by the | |
527 // browser, and (2) is ignored. | |
528 | |
529 NativeWebKeyboardEvent wke; | |
530 wke.type = WebKit::WebInputEvent::RawKeyDown; | |
531 wke.windowsKeyCode = e.key_code(); | |
532 wke.setKeyIdentifierFromWindowsKeyCode(); | |
533 | |
534 wke.text[0] = wke.unmodifiedText[0] = | |
535 static_cast<unsigned short>(gdk_keyval_to_unicode( | |
536 ui::GdkKeyCodeForWindowsKeyCode(e.key_code(), | |
537 e.IsShiftDown() ^ e.IsCapsLockDown()))); | |
538 | |
539 wke.modifiers = WebInputEventFlagsFromViewsEvent(e); | |
540 ForwardKeyboardEvent(wke); | |
541 | |
542 // send the keypress event | |
543 wke.type = WebKit::WebInputEvent::Char; | |
544 ForwardKeyboardEvent(wke); | |
545 | |
546 return TRUE; | 672 return TRUE; |
547 } | 673 } |
548 | 674 |
549 bool RenderWidgetHostViewViews::OnKeyReleased(const views::KeyEvent &e) { | 675 bool RenderWidgetHostViewViews::OnKeyReleased(const views::KeyEvent& e) { |
550 // TODO(bryeung): deal with input methods | 676 if (!ime_context_->FilterKeyEvent(e)) |
551 NativeWebKeyboardEvent wke; | 677 ForwardKeyEvent(e); |
552 | |
553 wke.type = WebKit::WebInputEvent::KeyUp; | |
554 wke.windowsKeyCode = e.key_code(); | |
555 wke.setKeyIdentifierFromWindowsKeyCode(); | |
556 | |
557 ForwardKeyboardEvent(wke); | |
558 | |
559 return TRUE; | 678 return TRUE; |
560 } | 679 } |
561 | 680 |
562 void RenderWidgetHostViewViews::DidGainFocus() { | 681 void RenderWidgetHostViewViews::DidGainFocus() { |
563 #if 0 | 682 #if 0 |
564 // TODO(anicolao): - is this needed/replicable? | 683 // TODO(anicolao): - is this needed/replicable? |
565 // Comes from the GTK equivalent. | 684 // Comes from the GTK equivalent. |
566 | 685 |
567 int x, y; | 686 int x, y; |
568 gtk_widget_get_pointer(native_view(), &x, &y); | 687 gtk_widget_get_pointer(native_view(), &x, &y); |
569 // http://crbug.com/13389 | 688 // http://crbug.com/13389 |
570 // If the cursor is in the render view, fake a mouse move event so that | 689 // If the cursor is in the render view, fake a mouse move event so that |
571 // webkit updates its state. Otherwise webkit might think the cursor is | 690 // webkit updates its state. Otherwise webkit might think the cursor is |
572 // somewhere it's not. | 691 // somewhere it's not. |
573 if (x >= 0 && y >= 0 && x < native_view()->allocation.width && | 692 if (x >= 0 && y >= 0 && x < native_view()->allocation.width && |
574 y < native_view()->allocation.height) { | 693 y < native_view()->allocation.height) { |
575 WebKit::WebMouseEvent fake_event; | 694 WebKit::WebMouseEvent fake_event; |
576 fake_event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 695 fake_event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
577 fake_event.modifiers = 0; | 696 fake_event.modifiers = 0; |
578 fake_event.windowX = fake_event.x = x; | 697 fake_event.windowX = fake_event.x = x; |
579 fake_event.windowY = fake_event.y = y; | 698 fake_event.windowY = fake_event.y = y; |
580 gdk_window_get_origin(native_view()->window, &x, &y); | 699 gdk_window_get_origin(native_view()->window, &x, &y); |
581 fake_event.globalX = fake_event.x + x; | 700 fake_event.globalX = fake_event.x + x; |
582 fake_event.globalY = fake_event.y + y; | 701 fake_event.globalY = fake_event.y + y; |
583 fake_event.type = WebKit::WebInputEvent::MouseMove; | 702 fake_event.type = WebKit::WebInputEvent::MouseMove; |
584 fake_event.button = WebKit::WebMouseEvent::ButtonNone; | 703 fake_event.button = WebKit::WebMouseEvent::ButtonNone; |
585 GetRenderWidgetHost()->ForwardMouseEvent(fake_event); | 704 GetRenderWidgetHost()->ForwardMouseEvent(fake_event); |
586 } | 705 } |
587 #endif | 706 #endif |
588 | 707 ime_context_->Focus(); |
589 ShowCurrentCursor(); | 708 ShowCurrentCursor(); |
590 GetRenderWidgetHost()->GotFocus(); | 709 GetRenderWidgetHost()->GotFocus(); |
591 } | 710 } |
592 | 711 |
593 void RenderWidgetHostViewViews::WillLoseFocus() { | 712 void RenderWidgetHostViewViews::WillLoseFocus() { |
594 // If we are showing a context menu, maintain the illusion that webkit has | 713 // If we are showing a context menu, maintain the illusion that webkit has |
595 // focus. | 714 // focus. |
596 if (!is_showing_context_menu_ && !is_hidden_) | 715 if (!is_showing_context_menu_ && !is_hidden_) |
597 GetRenderWidgetHost()->Blur(); | 716 GetRenderWidgetHost()->Blur(); |
| 717 ime_context_->Blur(); |
598 } | 718 } |
599 | 719 |
600 | 720 |
601 void RenderWidgetHostViewViews::ShowCurrentCursor() { | 721 void RenderWidgetHostViewViews::ShowCurrentCursor() { |
602 // The widget may not have a window. If that's the case, abort mission. This | 722 // The widget may not have a window. If that's the case, abort mission. This |
603 // is the same issue as that explained above in Paint(). | 723 // is the same issue as that explained above in Paint(). |
604 if (!GetInnerNativeView() || !GetInnerNativeView()->window) | 724 if (!GetInnerNativeView() || !GetInnerNativeView()->window) |
605 return; | 725 return; |
606 | 726 |
607 native_cursor_ = current_cursor_.GetNativeCursor(); | 727 native_cursor_ = current_cursor_.GetNativeCursor(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 wmevent.button = WebKit::WebMouseEvent::ButtonRight; | 773 wmevent.button = WebKit::WebMouseEvent::ButtonRight; |
654 } | 774 } |
655 if (event.IsLeftMouseButton()) { | 775 if (event.IsLeftMouseButton()) { |
656 wmevent.modifiers |= WebKit::WebInputEvent::LeftButtonDown; | 776 wmevent.modifiers |= WebKit::WebInputEvent::LeftButtonDown; |
657 wmevent.button = WebKit::WebMouseEvent::ButtonLeft; | 777 wmevent.button = WebKit::WebMouseEvent::ButtonLeft; |
658 } | 778 } |
659 | 779 |
660 return wmevent; | 780 return wmevent; |
661 } | 781 } |
662 | 782 |
663 void RenderWidgetHostViewViews::ForwardKeyboardEvent( | 783 void RenderWidgetHostViewViews::ForwardKeyEvent( |
| 784 const views::KeyEvent& event) { |
| 785 // This is how it works: |
| 786 // (1) If a RawKeyDown event is an accelerator for a reserved command (see |
| 787 // Browser::IsReservedCommand), then the command is executed. Otherwise, |
| 788 // the event is first sent off to the renderer. The renderer is also |
| 789 // notified whether the event would trigger an accelerator in the browser. |
| 790 // (2) A Char event is then sent to the renderer. |
| 791 // (3) If the renderer does not process the event in step (1), and the event |
| 792 // triggers an accelerator, then it will ignore the event in step (2). The |
| 793 // renderer also sends back notification to the browser for both steps (1) |
| 794 // and (2) about whether the events were processed or not. If the event |
| 795 // for (1) is not processed by the renderer, then it is processed by the |
| 796 // browser, and (2) is ignored. |
| 797 if (event.type() == ui::ET_KEY_PRESSED) { |
| 798 NativeWebKeyboardEvent wke; |
| 799 |
| 800 wke.type = WebKit::WebInputEvent::RawKeyDown; |
| 801 wke.windowsKeyCode = event.key_code(); |
| 802 wke.setKeyIdentifierFromWindowsKeyCode(); |
| 803 |
| 804 int keyval = ui::GdkKeyCodeForWindowsKeyCode(event.key_code(), |
| 805 event.IsShiftDown() ^ event.IsCapsLockDown()); |
| 806 |
| 807 wke.text[0] = wke.unmodifiedText[0] = |
| 808 static_cast<unsigned short>(gdk_keyval_to_unicode(keyval)); |
| 809 |
| 810 wke.modifiers = WebInputEventFlagsFromViewsEvent(event); |
| 811 |
| 812 ForwardWebKeyboardEvent(wke); |
| 813 |
| 814 wke.type = WebKit::WebInputEvent::Char; |
| 815 ForwardWebKeyboardEvent(wke); |
| 816 } else { |
| 817 NativeWebKeyboardEvent wke; |
| 818 |
| 819 wke.type = WebKit::WebInputEvent::KeyUp; |
| 820 wke.windowsKeyCode = event.key_code(); |
| 821 wke.setKeyIdentifierFromWindowsKeyCode(); |
| 822 ForwardWebKeyboardEvent(wke); |
| 823 } |
| 824 } |
| 825 |
| 826 void RenderWidgetHostViewViews::ForwardWebKeyboardEvent( |
664 const NativeWebKeyboardEvent& event) { | 827 const NativeWebKeyboardEvent& event) { |
665 if (!host_) | 828 if (!host_) |
666 return; | 829 return; |
667 | 830 |
668 EditCommands edit_commands; | 831 EditCommands edit_commands; |
669 #if 0 | 832 #if 0 |
670 TODO(bryeung): key bindings | 833 // TODO(bryeung): key bindings |
671 if (!event.skip_in_browser && | 834 if (!event.skip_in_browser && |
672 key_bindings_handler_->Match(event, &edit_commands)) { | 835 key_bindings_handler_->Match(event, &edit_commands)) { |
673 host_->ForwardEditCommandsForNextKeyEvent(edit_commands); | 836 host_->ForwardEditCommandsForNextKeyEvent(edit_commands); |
674 } | 837 } |
675 #endif | 838 #endif |
| 839 |
676 host_->ForwardKeyboardEvent(event); | 840 host_->ForwardKeyboardEvent(event); |
677 } | 841 } |
678 | 842 |
679 views::View::TouchStatus RenderWidgetHostViewViews::OnTouchEvent( | 843 views::View::TouchStatus RenderWidgetHostViewViews::OnTouchEvent( |
680 const views::TouchEvent& e) { | 844 const views::TouchEvent& e) { |
681 // Update the list of touch points first. | 845 // Update the list of touch points first. |
682 WebKit::WebTouchPoint* point = NULL; | 846 WebKit::WebTouchPoint* point = NULL; |
683 TouchStatus status = TOUCH_STATUS_UNKNOWN; | 847 TouchStatus status = TOUCH_STATUS_UNKNOWN; |
684 | 848 |
685 switch (e.type()) { | 849 switch (e.type()) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 } | 939 } |
776 | 940 |
777 // static | 941 // static |
778 RenderWidgetHostView* | 942 RenderWidgetHostView* |
779 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 943 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
780 gfx::NativeView widget) { | 944 gfx::NativeView widget) { |
781 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 945 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
782 kRenderWidgetHostViewKey); | 946 kRenderWidgetHostViewKey); |
783 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 947 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
784 } | 948 } |
OLD | NEW |