| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/gtk_im_context_wrapper.h" | 5 #include "chrome/browser/renderer_host/gtk_im_context_wrapper.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 // 7. keyup Backspace (unfiltered) | 139 // 7. keyup Backspace (unfiltered) |
| 140 // | 140 // |
| 141 // In this case, the input box will be in a strange state if keydown | 141 // In this case, the input box will be in a strange state if keydown |
| 142 // Backspace is sent to webkit before commit "a" and preedit end. | 142 // Backspace is sent to webkit before commit "a" and preedit end. |
| 143 ProcessInputMethodResult(event, filtered); | 143 ProcessInputMethodResult(event, filtered); |
| 144 | 144 |
| 145 // Send unfiltered keydown and keyup events after sending IME result. | 145 // Send unfiltered keydown and keyup events after sending IME result. |
| 146 if (event->type == GDK_KEY_PRESS && !filtered) | 146 if (event->type == GDK_KEY_PRESS && !filtered) |
| 147 ProcessUnfilteredKeyPressEvent(&wke); | 147 ProcessUnfilteredKeyPressEvent(&wke); |
| 148 else if (event->type == GDK_KEY_RELEASE) | 148 else if (event->type == GDK_KEY_RELEASE) |
| 149 host_view_->GetRenderWidgetHost()->ForwardKeyboardEvent(wke); | 149 host_view_->ForwardKeyboardEvent(wke); |
| 150 | 150 |
| 151 // End of key event processing. | 151 // End of key event processing. |
| 152 is_in_key_event_handler_ = false; | 152 is_in_key_event_handler_ = false; |
| 153 } | 153 } |
| 154 | 154 |
| 155 void GtkIMContextWrapper::UpdateStatus(int control, | 155 void GtkIMContextWrapper::UpdateStatus(int control, |
| 156 const gfx::Rect& caret_rect) { | 156 const gfx::Rect& caret_rect) { |
| 157 // The renderer has updated its IME status. | 157 // The renderer has updated its IME status. |
| 158 // Control the GtkIMContext object according to this status. | 158 // Control the GtkIMContext object according to this status. |
| 159 if (!context_ || !is_focused_) | 159 if (!context_ || !is_focused_) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 wke->setKeyIdentifierFromWindowsKeyCode(); | 284 wke->setKeyIdentifierFromWindowsKeyCode(); |
| 285 // Prevent RenderView::UnhandledKeyboardEvent() from processing it. | 285 // Prevent RenderView::UnhandledKeyboardEvent() from processing it. |
| 286 // Otherwise unexpected result may occur. For example if it's a | 286 // Otherwise unexpected result may occur. For example if it's a |
| 287 // Backspace key event, the browser may go back to previous page. | 287 // Backspace key event, the browser may go back to previous page. |
| 288 if (wke->os_event) { | 288 if (wke->os_event) { |
| 289 wke->os_event->keyval = GDK_VoidSymbol; | 289 wke->os_event->keyval = GDK_VoidSymbol; |
| 290 wke->os_event->hardware_keycode = 0; | 290 wke->os_event->hardware_keycode = 0; |
| 291 wke->os_event->state = 0; | 291 wke->os_event->state = 0; |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 host_view_->GetRenderWidgetHost()->ForwardKeyboardEvent(*wke); | 294 host_view_->ForwardKeyboardEvent(*wke); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void GtkIMContextWrapper::ProcessUnfilteredKeyPressEvent( | 297 void GtkIMContextWrapper::ProcessUnfilteredKeyPressEvent( |
| 298 NativeWebKeyboardEvent* wke) { | 298 NativeWebKeyboardEvent* wke) { |
| 299 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); | |
| 300 | |
| 301 // Send keydown event as it, because it's not filtered by IME. | 299 // Send keydown event as it, because it's not filtered by IME. |
| 302 host->ForwardKeyboardEvent(*wke); | 300 host_view_->ForwardKeyboardEvent(*wke); |
| 303 | 301 |
| 304 // IME is disabled by WebKit or the GtkIMContext object cannot handle | 302 // IME is disabled by WebKit or the GtkIMContext object cannot handle |
| 305 // this key event. | 303 // this key event. |
| 306 // This case is caused by two reasons: | 304 // This case is caused by two reasons: |
| 307 // 1. The given key event is a control-key event, (e.g. return, page up, | 305 // 1. The given key event is a control-key event, (e.g. return, page up, |
| 308 // page down, tab, arrows, etc.) or; | 306 // page down, tab, arrows, etc.) or; |
| 309 // 2. The given key event is not a control-key event but printable | 307 // 2. The given key event is not a control-key event but printable |
| 310 // characters aren't assigned to the event, (e.g. alt+d, etc.) | 308 // characters aren't assigned to the event, (e.g. alt+d, etc.) |
| 311 // Create a Char event manually from this key event and send it to the | 309 // Create a Char event manually from this key event and send it to the |
| 312 // renderer when this Char event contains a printable character which | 310 // renderer when this Char event contains a printable character which |
| 313 // should be processed by WebKit. | 311 // should be processed by WebKit. |
| 314 // isSystemKey will be set to true if this key event has Alt modifier, | 312 // isSystemKey will be set to true if this key event has Alt modifier, |
| 315 // see WebInputEventFactory::keyboardEvent() for details. | 313 // see WebInputEventFactory::keyboardEvent() for details. |
| 316 if (wke->text[0]) { | 314 if (wke->text[0]) { |
| 317 wke->type = WebKit::WebInputEvent::Char; | 315 wke->type = WebKit::WebInputEvent::Char; |
| 318 host->ForwardKeyboardEvent(*wke); | 316 host_view_->ForwardKeyboardEvent(*wke); |
| 319 } | 317 } |
| 320 } | 318 } |
| 321 | 319 |
| 322 void GtkIMContextWrapper::ProcessInputMethodResult(const GdkEventKey* event, | 320 void GtkIMContextWrapper::ProcessInputMethodResult(const GdkEventKey* event, |
| 323 bool filtered) { | 321 bool filtered) { |
| 324 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); | 322 RenderWidgetHost* host = host_view_->GetRenderWidgetHost(); |
| 325 bool committed = false; | 323 bool committed = false; |
| 326 // We do commit before preedit change, so that we can optimize some | 324 // We do commit before preedit change, so that we can optimize some |
| 327 // unnecessary preedit changes. | 325 // unnecessary preedit changes. |
| 328 if (commit_text_.length()) { | 326 if (commit_text_.length()) { |
| 329 if (filtered && NeedCommitByForwardingCharEvent()) { | 327 if (filtered && NeedCommitByForwardingCharEvent()) { |
| 330 // Send a Char event when we input a composed character without IMEs | 328 // Send a Char event when we input a composed character without IMEs |
| 331 // so that this event is to be dispatched to onkeypress() handlers, | 329 // so that this event is to be dispatched to onkeypress() handlers, |
| 332 // autofill, etc. | 330 // autofill, etc. |
| 333 // Only commit text generated by a filtered key down event can be sent | 331 // Only commit text generated by a filtered key down event can be sent |
| 334 // as a Char event, because a unfiltered key down event will probably | 332 // as a Char event, because a unfiltered key down event will probably |
| 335 // generate another Char event. | 333 // generate another Char event. |
| 336 // TODO(james.su@gmail.com): Is it necessary to support non BMP chars | 334 // TODO(james.su@gmail.com): Is it necessary to support non BMP chars |
| 337 // here? | 335 // here? |
| 338 NativeWebKeyboardEvent char_event(commit_text_[0], | 336 NativeWebKeyboardEvent char_event(commit_text_[0], |
| 339 event->state, | 337 event->state, |
| 340 base::Time::Now().ToDoubleT()); | 338 base::Time::Now().ToDoubleT()); |
| 341 host->ForwardKeyboardEvent(char_event); | 339 host_view_->ForwardKeyboardEvent(char_event); |
| 342 } else { | 340 } else { |
| 343 committed = true; | 341 committed = true; |
| 344 // Send an IME event. | 342 // Send an IME event. |
| 345 // Unlike a Char event, an IME event is NOT dispatched to onkeypress() | 343 // Unlike a Char event, an IME event is NOT dispatched to onkeypress() |
| 346 // handlers or autofill. | 344 // handlers or autofill. |
| 347 host->ImeConfirmComposition(commit_text_); | 345 host->ImeConfirmComposition(commit_text_); |
| 348 // Set this flag to false, as this composition session has been | 346 // Set this flag to false, as this composition session has been |
| 349 // finished. | 347 // finished. |
| 350 is_composing_text_ = false; | 348 is_composing_text_ = false; |
| 351 } | 349 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 508 |
| 511 void GtkIMContextWrapper::HandleHostViewRealizeThunk( | 509 void GtkIMContextWrapper::HandleHostViewRealizeThunk( |
| 512 GtkWidget* widget, GtkIMContextWrapper* self) { | 510 GtkWidget* widget, GtkIMContextWrapper* self) { |
| 513 self->HandleHostViewRealize(widget); | 511 self->HandleHostViewRealize(widget); |
| 514 } | 512 } |
| 515 | 513 |
| 516 void GtkIMContextWrapper::HandleHostViewUnrealizeThunk( | 514 void GtkIMContextWrapper::HandleHostViewUnrealizeThunk( |
| 517 GtkWidget* widget, GtkIMContextWrapper* self) { | 515 GtkWidget* widget, GtkIMContextWrapper* self) { |
| 518 self->HandleHostViewUnrealize(); | 516 self->HandleHostViewUnrealize(); |
| 519 } | 517 } |
| OLD | NEW |