OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h" | 48 #include "content/browser/renderer_host/render_widget_host_view_event_handler.h" |
49 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber
.h" | 49 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber
.h" |
50 #include "content/browser/renderer_host/resize_lock.h" | 50 #include "content/browser/renderer_host/resize_lock.h" |
51 #include "content/browser/renderer_host/text_input_manager.h" | 51 #include "content/browser/renderer_host/text_input_manager.h" |
52 #include "content/browser/web_contents/web_contents_view_aura.h" | 52 #include "content/browser/web_contents/web_contents_view_aura.h" |
53 #include "content/common/host_shared_bitmap_manager.h" | 53 #include "content/common/host_shared_bitmap_manager.h" |
54 #include "content/common/input/synthetic_web_input_event_builders.h" | 54 #include "content/common/input/synthetic_web_input_event_builders.h" |
55 #include "content/common/input_messages.h" | 55 #include "content/common/input_messages.h" |
56 #include "content/common/text_input_state.h" | 56 #include "content/common/text_input_state.h" |
57 #include "content/common/view_messages.h" | 57 #include "content/common/view_messages.h" |
| 58 #include "content/public/browser/keyboard_event_processing_result.h" |
58 #include "content/public/browser/render_widget_host_view.h" | 59 #include "content/public/browser/render_widget_host_view.h" |
59 #include "content/public/browser/web_contents_view_delegate.h" | 60 #include "content/public/browser/web_contents_view_delegate.h" |
60 #include "content/public/common/content_features.h" | 61 #include "content/public/common/content_features.h" |
61 #include "content/public/common/context_menu_params.h" | 62 #include "content/public/common/context_menu_params.h" |
62 #include "content/public/test/mock_render_process_host.h" | 63 #include "content/public/test/mock_render_process_host.h" |
63 #include "content/public/test/test_browser_context.h" | 64 #include "content/public/test/test_browser_context.h" |
64 #include "content/test/test_render_view_host.h" | 65 #include "content/test/test_render_view_host.h" |
65 #include "content/test/test_web_contents.h" | 66 #include "content/test/test_web_contents.h" |
66 #include "ipc/ipc_message.h" | 67 #include "ipc/ipc_message.h" |
67 #include "ipc/ipc_test_sink.h" | 68 #include "ipc/ipc_test_sink.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 return !!focused_widget_ ? focused_widget_ : widget_host; | 204 return !!focused_widget_ ? focused_widget_ : widget_host; |
204 } | 205 } |
205 void set_focused_widget(RenderWidgetHostImpl* focused_widget) { | 206 void set_focused_widget(RenderWidgetHostImpl* focused_widget) { |
206 focused_widget_ = focused_widget; | 207 focused_widget_ = focused_widget; |
207 } | 208 } |
208 | 209 |
209 double get_last_device_scale_factor() { return last_device_scale_factor_; } | 210 double get_last_device_scale_factor() { return last_device_scale_factor_; } |
210 void UpdateDeviceScaleFactor(double device_scale_factor) override { | 211 void UpdateDeviceScaleFactor(double device_scale_factor) override { |
211 last_device_scale_factor_ = device_scale_factor; | 212 last_device_scale_factor_ = device_scale_factor; |
212 } | 213 } |
| 214 void set_pre_handle_keyboard_event_result( |
| 215 KeyboardEventProcessingResult result) { |
| 216 pre_handle_keyboard_event_result_ = result; |
| 217 } |
213 | 218 |
214 protected: | 219 protected: |
215 // RenderWidgetHostDelegate: | 220 // RenderWidgetHostDelegate: |
216 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 221 KeyboardEventProcessingResult PreHandleKeyboardEvent( |
217 bool* is_keyboard_shortcut) override { | 222 const NativeWebKeyboardEvent& event) override { |
218 last_event_.reset(new NativeWebKeyboardEvent(event)); | 223 last_event_.reset(new NativeWebKeyboardEvent(event)); |
219 return true; | 224 return pre_handle_keyboard_event_result_; |
220 } | 225 } |
221 void Cut() override {} | 226 void Cut() override {} |
222 void Copy() override {} | 227 void Copy() override {} |
223 void Paste() override {} | 228 void Paste() override {} |
224 void SelectAll() override {} | 229 void SelectAll() override {} |
225 void SendScreenRects() override { | 230 void SendScreenRects() override { |
226 if (rwh_) | 231 if (rwh_) |
227 rwh_->SendScreenRects(); | 232 rwh_->SendScreenRects(); |
228 } | 233 } |
229 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; } | 234 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; } |
230 | 235 |
231 private: | 236 private: |
232 std::unique_ptr<NativeWebKeyboardEvent> last_event_; | 237 std::unique_ptr<NativeWebKeyboardEvent> last_event_; |
233 RenderWidgetHostImpl* rwh_; | 238 RenderWidgetHostImpl* rwh_; |
234 bool is_fullscreen_; | 239 bool is_fullscreen_; |
235 TextInputManager text_input_manager_; | 240 TextInputManager text_input_manager_; |
236 RenderWidgetHostImpl* focused_widget_; | 241 RenderWidgetHostImpl* focused_widget_; |
237 double last_device_scale_factor_; | 242 double last_device_scale_factor_; |
| 243 KeyboardEventProcessingResult pre_handle_keyboard_event_result_ = |
| 244 KeyboardEventProcessingResult::HANDLED; |
238 | 245 |
239 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate); | 246 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate); |
240 }; | 247 }; |
241 | 248 |
242 // Simple observer that keeps track of changes to a window for tests. | 249 // Simple observer that keeps track of changes to a window for tests. |
243 class TestWindowObserver : public aura::WindowObserver { | 250 class TestWindowObserver : public aura::WindowObserver { |
244 public: | 251 public: |
245 explicit TestWindowObserver(aura::Window* window_to_observe) | 252 explicit TestWindowObserver(aura::Window* window_to_observe) |
246 : window_(window_to_observe) { | 253 : window_(window_to_observe) { |
247 window_->AddObserver(this); | 254 window_->AddObserver(this); |
(...skipping 4014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4262 // Checks key event codes. | 4269 // Checks key event codes. |
4263 TEST_F(RenderWidgetHostViewAuraTest, KeyEvent) { | 4270 TEST_F(RenderWidgetHostViewAuraTest, KeyEvent) { |
4264 view_->InitAsChild(nullptr); | 4271 view_->InitAsChild(nullptr); |
4265 view_->Show(); | 4272 view_->Show(); |
4266 | 4273 |
4267 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, | 4274 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::DomCode::US_A, |
4268 ui::EF_NONE); | 4275 ui::EF_NONE); |
4269 view_->OnKeyEvent(&key_event); | 4276 view_->OnKeyEvent(&key_event); |
4270 | 4277 |
4271 const NativeWebKeyboardEvent* event = delegates_.back()->last_event(); | 4278 const NativeWebKeyboardEvent* event = delegates_.back()->last_event(); |
4272 EXPECT_NE(nullptr, event); | 4279 ASSERT_TRUE(event); |
4273 if (event) { | 4280 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode); |
4274 EXPECT_EQ(key_event.key_code(), event->windowsKeyCode); | 4281 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()), |
4275 EXPECT_EQ(ui::KeycodeConverter::DomCodeToNativeKeycode(key_event.code()), | 4282 event->nativeKeyCode); |
4276 event->nativeKeyCode); | 4283 } |
4277 } | 4284 |
| 4285 TEST_F(RenderWidgetHostViewAuraTest, KeyEventsHandled) { |
| 4286 view_->InitAsChild(nullptr); |
| 4287 view_->Show(); |
| 4288 |
| 4289 ui::KeyEvent key_event1(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 4290 view_->OnKeyEvent(&key_event1); |
| 4291 // Normally event should be handled. |
| 4292 EXPECT_TRUE(key_event1.handled()); |
| 4293 |
| 4294 ASSERT_FALSE(delegates_.empty()); |
| 4295 // Make the delegate mark the event as not-handled. |
| 4296 delegates_.back()->set_pre_handle_keyboard_event_result( |
| 4297 KeyboardEventProcessingResult::HANDLED_DONT_UPDATE_EVENT); |
| 4298 ui::KeyEvent key_event2(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 4299 view_->OnKeyEvent(&key_event2); |
| 4300 EXPECT_FALSE(key_event2.handled()); |
4278 } | 4301 } |
4279 | 4302 |
4280 TEST_F(RenderWidgetHostViewAuraTest, SetCanScrollForWebMouseWheelEvent) { | 4303 TEST_F(RenderWidgetHostViewAuraTest, SetCanScrollForWebMouseWheelEvent) { |
4281 view_->InitAsChild(nullptr); | 4304 view_->InitAsChild(nullptr); |
4282 view_->Show(); | 4305 view_->Show(); |
4283 | 4306 |
4284 sink_->ClearMessages(); | 4307 sink_->ClearMessages(); |
4285 | 4308 |
4286 // Simulates the mouse wheel event with ctrl modifier applied. | 4309 // Simulates the mouse wheel event with ctrl modifier applied. |
4287 ui::MouseWheelEvent event(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(), | 4310 ui::MouseWheelEvent event(gfx::Vector2d(1, 1), gfx::Point(), gfx::Point(), |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5007 // There is no composition in the beginning. | 5030 // There is no composition in the beginning. |
5008 EXPECT_FALSE(has_composition_text()); | 5031 EXPECT_FALSE(has_composition_text()); |
5009 SetHasCompositionTextToTrue(); | 5032 SetHasCompositionTextToTrue(); |
5010 view->ImeCancelComposition(); | 5033 view->ImeCancelComposition(); |
5011 // The composition must have been canceled. | 5034 // The composition must have been canceled. |
5012 EXPECT_FALSE(has_composition_text()); | 5035 EXPECT_FALSE(has_composition_text()); |
5013 } | 5036 } |
5014 } | 5037 } |
5015 | 5038 |
5016 } // namespace content | 5039 } // namespace content |
OLD | NEW |