| 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 "content/public/browser/native_web_keyboard_event.h" | 5 #include "content/public/browser/native_web_keyboard_event.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/events/base_event_utils.h" | 8 #include "ui/events/base_event_utils.h" |
| 9 #include "ui/events/blink/web_input_event.h" | 9 #include "ui/events/blink/web_input_event.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 | 13 |
| 14 // We need to copy |os_event| in NativeWebKeyboardEvent because it is | 14 // We need to copy |os_event| in NativeWebKeyboardEvent because it is |
| 15 // queued in RenderWidgetHost and may be passed and used | 15 // queued in RenderWidgetHost and may be passed and used |
| 16 // RenderViewHostDelegate::HandledKeybardEvent after the original aura | 16 // RenderViewHostDelegate::HandledKeybardEvent after the original aura |
| 17 // event is destroyed. | 17 // event is destroyed. |
| 18 ui::Event* CopyEvent(const ui::Event* event) { | 18 ui::Event* CopyEvent(const ui::Event* event) { |
| 19 return event ? ui::Event::Clone(*event).release() : nullptr; | 19 return event ? ui::Event::Clone(*event).release() : nullptr; |
| 20 } | 20 } |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 using blink::WebKeyboardEvent; | 24 using blink::WebKeyboardEvent; |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 NativeWebKeyboardEvent::NativeWebKeyboardEvent() | 28 NativeWebKeyboardEvent::NativeWebKeyboardEvent() |
| 29 : os_event(NULL), | 29 : os_event(NULL), |
| 30 skip_in_browser(false) { | 30 skip_in_browser(false), |
| 31 is_synthetic(false) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) | 34 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) |
| 34 : NativeWebKeyboardEvent(static_cast<ui::KeyEvent&>(*native_event)) { | 35 : NativeWebKeyboardEvent(static_cast<ui::KeyEvent&>(*native_event)) { |
| 35 } | 36 } |
| 36 | 37 |
| 37 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const ui::KeyEvent& key_event) | 38 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const ui::KeyEvent& key_event) |
| 38 : WebKeyboardEvent(ui::MakeWebKeyboardEvent(key_event)), | 39 : WebKeyboardEvent(ui::MakeWebKeyboardEvent(key_event)), |
| 39 os_event(CopyEvent(&key_event)), | 40 os_event(CopyEvent(&key_event)), |
| 40 skip_in_browser(false) {} | 41 skip_in_browser(false), |
| 42 is_synthetic(false) {} |
| 41 | 43 |
| 42 NativeWebKeyboardEvent::NativeWebKeyboardEvent( | 44 NativeWebKeyboardEvent::NativeWebKeyboardEvent( |
| 43 const NativeWebKeyboardEvent& other) | 45 const NativeWebKeyboardEvent& other) |
| 44 : WebKeyboardEvent(other), | 46 : WebKeyboardEvent(other), |
| 45 os_event(CopyEvent(other.os_event)), | 47 os_event(CopyEvent(other.os_event)), |
| 46 skip_in_browser(other.skip_in_browser) { | 48 skip_in_browser(other.skip_in_browser), |
| 49 is_synthetic(false) { |
| 47 } | 50 } |
| 48 | 51 |
| 49 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const ui::KeyEvent& key_event, | 52 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const ui::KeyEvent& key_event, |
| 50 base::char16 character) | 53 base::char16 character) |
| 51 : WebKeyboardEvent(ui::MakeWebKeyboardEvent(key_event)), | 54 : WebKeyboardEvent(ui::MakeWebKeyboardEvent(key_event)), |
| 52 os_event(NULL), | 55 os_event(NULL), |
| 53 skip_in_browser(false) { | 56 skip_in_browser(false), |
| 57 is_synthetic(false) { |
| 54 type = blink::WebInputEvent::Char; | 58 type = blink::WebInputEvent::Char; |
| 55 windowsKeyCode = character; | 59 windowsKeyCode = character; |
| 56 text[0] = character; | 60 text[0] = character; |
| 57 unmodifiedText[0] = character; | 61 unmodifiedText[0] = character; |
| 58 } | 62 } |
| 59 | 63 |
| 60 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( | 64 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( |
| 61 const NativeWebKeyboardEvent& other) { | 65 const NativeWebKeyboardEvent& other) { |
| 62 WebKeyboardEvent::operator=(other); | 66 WebKeyboardEvent::operator=(other); |
| 63 delete os_event; | 67 delete os_event; |
| 64 os_event = CopyEvent(other.os_event); | 68 os_event = CopyEvent(other.os_event); |
| 65 skip_in_browser = other.skip_in_browser; | 69 skip_in_browser = other.skip_in_browser; |
| 70 is_synthetic = other.is_synthetic; |
| 66 return *this; | 71 return *this; |
| 67 } | 72 } |
| 68 | 73 |
| 69 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { | 74 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { |
| 70 delete os_event; | 75 delete os_event; |
| 71 } | 76 } |
| 72 | 77 |
| 73 } // namespace content | 78 } // namespace content |
| OLD | NEW |