| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 OverscrollMode current_mode_; | 156 OverscrollMode current_mode_; |
| 157 OverscrollMode completed_mode_; | 157 OverscrollMode completed_mode_; |
| 158 float delta_x_; | 158 float delta_x_; |
| 159 float delta_y_; | 159 float delta_y_; |
| 160 | 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate); | 161 DISALLOW_COPY_AND_ASSIGN(TestOverscrollDelegate); |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { | 164 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate { |
| 165 public: | 165 public: |
| 166 MockRenderWidgetHostDelegate() : rwh_(nullptr), is_fullscreen_(false) {} | 166 MockRenderWidgetHostDelegate() |
| 167 : rwh_(nullptr), is_fullscreen_(false), last_device_scale_factor_(0.0) {} |
| 167 ~MockRenderWidgetHostDelegate() override {} | 168 ~MockRenderWidgetHostDelegate() override {} |
| 168 const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); } | 169 const NativeWebKeyboardEvent* last_event() const { return last_event_.get(); } |
| 169 void set_widget_host(RenderWidgetHostImpl* rwh) { rwh_ = rwh; } | 170 void set_widget_host(RenderWidgetHostImpl* rwh) { rwh_ = rwh; } |
| 170 void set_is_fullscreen(bool is_fullscreen) { is_fullscreen_ = is_fullscreen; } | 171 void set_is_fullscreen(bool is_fullscreen) { is_fullscreen_ = is_fullscreen; } |
| 171 TextInputManager* GetTextInputManager() override { | 172 TextInputManager* GetTextInputManager() override { |
| 172 return &text_input_manager_; | 173 return &text_input_manager_; |
| 173 } | 174 } |
| 174 | 175 |
| 176 double get_last_device_scale_factor() { return last_device_scale_factor_; } |
| 177 void UpdateDeviceScaleFactor(double device_scale_factor) override { |
| 178 last_device_scale_factor_ = device_scale_factor; |
| 179 } |
| 180 |
| 175 protected: | 181 protected: |
| 176 // RenderWidgetHostDelegate: | 182 // RenderWidgetHostDelegate: |
| 177 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 183 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 178 bool* is_keyboard_shortcut) override { | 184 bool* is_keyboard_shortcut) override { |
| 179 last_event_.reset(new NativeWebKeyboardEvent(event)); | 185 last_event_.reset(new NativeWebKeyboardEvent(event)); |
| 180 return true; | 186 return true; |
| 181 } | 187 } |
| 182 void Cut() override {} | 188 void Cut() override {} |
| 183 void Copy() override {} | 189 void Copy() override {} |
| 184 void Paste() override {} | 190 void Paste() override {} |
| 185 void SelectAll() override {} | 191 void SelectAll() override {} |
| 186 void SendScreenRects() override { | 192 void SendScreenRects() override { |
| 187 if (rwh_) | 193 if (rwh_) |
| 188 rwh_->SendScreenRects(); | 194 rwh_->SendScreenRects(); |
| 189 } | 195 } |
| 190 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; } | 196 bool IsFullscreenForCurrentTab() const override { return is_fullscreen_; } |
| 191 | 197 |
| 192 private: | 198 private: |
| 193 std::unique_ptr<NativeWebKeyboardEvent> last_event_; | 199 std::unique_ptr<NativeWebKeyboardEvent> last_event_; |
| 194 RenderWidgetHostImpl* rwh_; | 200 RenderWidgetHostImpl* rwh_; |
| 195 bool is_fullscreen_; | 201 bool is_fullscreen_; |
| 196 TextInputManager text_input_manager_; | 202 TextInputManager text_input_manager_; |
| 203 double last_device_scale_factor_; |
| 197 | 204 |
| 198 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate); | 205 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostDelegate); |
| 199 }; | 206 }; |
| 200 | 207 |
| 201 // Simple observer that keeps track of changes to a window for tests. | 208 // Simple observer that keeps track of changes to a window for tests. |
| 202 class TestWindowObserver : public aura::WindowObserver { | 209 class TestWindowObserver : public aura::WindowObserver { |
| 203 public: | 210 public: |
| 204 explicit TestWindowObserver(aura::Window* window_to_observe) | 211 explicit TestWindowObserver(aura::Window* window_to_observe) |
| 205 : window_(window_to_observe) { | 212 : window_(window_to_observe) { |
| 206 window_->AddObserver(this); | 213 window_->AddObserver(this); |
| (...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 "100x100", | 1441 "100x100", |
| 1435 std::get<0>(params).physical_backing_size.ToString()); // backing size | 1442 std::get<0>(params).physical_backing_size.ToString()); // backing size |
| 1436 } | 1443 } |
| 1437 | 1444 |
| 1438 widget_host_->ResetSizeAndRepaintPendingFlags(); | 1445 widget_host_->ResetSizeAndRepaintPendingFlags(); |
| 1439 sink_->ClearMessages(); | 1446 sink_->ClearMessages(); |
| 1440 | 1447 |
| 1441 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f); | 1448 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f); |
| 1442 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString()); | 1449 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString()); |
| 1443 // Extra ScreenInfoChanged message for |parent_view_|. | 1450 // Extra ScreenInfoChanged message for |parent_view_|. |
| 1444 EXPECT_EQ(1u, sink_->message_count()); | 1451 EXPECT_EQ(0u, sink_->message_count()); |
| 1445 { | 1452 auto view_delegate = static_cast<MockRenderWidgetHostDelegate*>( |
| 1446 const IPC::Message* msg = sink_->GetMessageAt(0); | 1453 static_cast<RenderWidgetHostImpl*>(view_->GetRenderWidgetHost()) |
| 1447 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 1454 ->delegate()); |
| 1448 ViewMsg_Resize::Param params; | 1455 EXPECT_EQ(2.0f, view_delegate->get_last_device_scale_factor()); |
| 1449 ViewMsg_Resize::Read(msg, ¶ms); | |
| 1450 EXPECT_EQ(2.0f, std::get<0>(params).screen_info.deviceScaleFactor); | |
| 1451 EXPECT_EQ("100x100", std::get<0>(params).new_size.ToString()); // dip size | |
| 1452 EXPECT_EQ( | |
| 1453 "200x200", | |
| 1454 std::get<0>(params).physical_backing_size.ToString()); // backing size | |
| 1455 } | |
| 1456 | 1456 |
| 1457 widget_host_->ResetSizeAndRepaintPendingFlags(); | 1457 widget_host_->ResetSizeAndRepaintPendingFlags(); |
| 1458 sink_->ClearMessages(); | 1458 sink_->ClearMessages(); |
| 1459 | 1459 |
| 1460 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f); | 1460 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f); |
| 1461 // Extra ScreenInfoChanged message for |parent_view_|. | 1461 // Extra ScreenInfoChanged message for |parent_view_|. |
| 1462 EXPECT_EQ(1u, sink_->message_count()); | 1462 EXPECT_EQ(0u, sink_->message_count()); |
| 1463 EXPECT_EQ(1.0f, view_delegate->get_last_device_scale_factor()); |
| 1463 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); | 1464 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); |
| 1464 { | |
| 1465 const IPC::Message* msg = sink_->GetMessageAt(0); | |
| 1466 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | |
| 1467 ViewMsg_Resize::Param params; | |
| 1468 ViewMsg_Resize::Read(msg, ¶ms); | |
| 1469 EXPECT_EQ(1.0f, std::get<0>(params).screen_info.deviceScaleFactor); | |
| 1470 EXPECT_EQ("100x100", std::get<0>(params).new_size.ToString()); // dip size | |
| 1471 EXPECT_EQ( | |
| 1472 "100x100", | |
| 1473 std::get<0>(params).physical_backing_size.ToString()); // backing size | |
| 1474 } | |
| 1475 } | 1465 } |
| 1476 | 1466 |
| 1477 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched | 1467 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched |
| 1478 // to the renderer at the correct times. | 1468 // to the renderer at the correct times. |
| 1479 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) { | 1469 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) { |
| 1480 view_->InitAsChild(nullptr); | 1470 view_->InitAsChild(nullptr); |
| 1481 aura::client::ParentWindowWithContext( | 1471 aura::client::ParentWindowWithContext( |
| 1482 view_->GetNativeView(), | 1472 view_->GetNativeView(), |
| 1483 parent_view_->GetNativeView()->GetRootWindow(), | 1473 parent_view_->GetNativeView()->GetRootWindow(), |
| 1484 gfx::Rect()); | 1474 gfx::Rect()); |
| (...skipping 3048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4533 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); | 4523 EXPECT_TRUE(text_input_client()->GetSelectionRange(&range_from_client)); |
| 4534 EXPECT_EQ(expected_range, range_from_client); | 4524 EXPECT_EQ(expected_range, range_from_client); |
| 4535 | 4525 |
| 4536 // Changing range to make sure that the next view has a different text | 4526 // Changing range to make sure that the next view has a different text |
| 4537 // selection. | 4527 // selection. |
| 4538 expected_range.set_end(expected_range.end() + 1U); | 4528 expected_range.set_end(expected_range.end() + 1U); |
| 4539 } | 4529 } |
| 4540 } | 4530 } |
| 4541 | 4531 |
| 4542 } // namespace content | 4532 } // namespace content |
| OLD | NEW |