| 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 1213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 "100x100", | 1427 "100x100", |
| 1421 std::get<0>(params).physical_backing_size.ToString()); // backing size | 1428 std::get<0>(params).physical_backing_size.ToString()); // backing size |
| 1422 } | 1429 } |
| 1423 | 1430 |
| 1424 widget_host_->ResetSizeAndRepaintPendingFlags(); | 1431 widget_host_->ResetSizeAndRepaintPendingFlags(); |
| 1425 sink_->ClearMessages(); | 1432 sink_->ClearMessages(); |
| 1426 | 1433 |
| 1427 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f); | 1434 aura_test_helper_->test_screen()->SetDeviceScaleFactor(2.0f); |
| 1428 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString()); | 1435 EXPECT_EQ("200x200", view_->GetPhysicalBackingSize().ToString()); |
| 1429 // Extra ScreenInfoChanged message for |parent_view_|. | 1436 // Extra ScreenInfoChanged message for |parent_view_|. |
| 1430 EXPECT_EQ(1u, sink_->message_count()); | 1437 EXPECT_EQ(0u, sink_->message_count()); |
| 1431 { | 1438 auto view_delegate = static_cast<MockRenderWidgetHostDelegate*>( |
| 1432 const IPC::Message* msg = sink_->GetMessageAt(0); | 1439 static_cast<RenderWidgetHostImpl*>(view_->GetRenderWidgetHost()) |
| 1433 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | 1440 ->delegate()); |
| 1434 ViewMsg_Resize::Param params; | 1441 EXPECT_EQ(2.0f, view_delegate->get_last_device_scale_factor()); |
| 1435 ViewMsg_Resize::Read(msg, ¶ms); | |
| 1436 EXPECT_EQ(2.0f, std::get<0>(params).screen_info.deviceScaleFactor); | |
| 1437 EXPECT_EQ("100x100", std::get<0>(params).new_size.ToString()); // dip size | |
| 1438 EXPECT_EQ( | |
| 1439 "200x200", | |
| 1440 std::get<0>(params).physical_backing_size.ToString()); // backing size | |
| 1441 } | |
| 1442 | 1442 |
| 1443 widget_host_->ResetSizeAndRepaintPendingFlags(); | 1443 widget_host_->ResetSizeAndRepaintPendingFlags(); |
| 1444 sink_->ClearMessages(); | 1444 sink_->ClearMessages(); |
| 1445 | 1445 |
| 1446 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f); | 1446 aura_test_helper_->test_screen()->SetDeviceScaleFactor(1.0f); |
| 1447 // Extra ScreenInfoChanged message for |parent_view_|. | 1447 // Extra ScreenInfoChanged message for |parent_view_|. |
| 1448 EXPECT_EQ(1u, sink_->message_count()); | 1448 EXPECT_EQ(0u, sink_->message_count()); |
| 1449 EXPECT_EQ(1.0f, view_delegate->get_last_device_scale_factor()); |
| 1449 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); | 1450 EXPECT_EQ("100x100", view_->GetPhysicalBackingSize().ToString()); |
| 1450 { | |
| 1451 const IPC::Message* msg = sink_->GetMessageAt(0); | |
| 1452 EXPECT_EQ(ViewMsg_Resize::ID, msg->type()); | |
| 1453 ViewMsg_Resize::Param params; | |
| 1454 ViewMsg_Resize::Read(msg, ¶ms); | |
| 1455 EXPECT_EQ(1.0f, std::get<0>(params).screen_info.deviceScaleFactor); | |
| 1456 EXPECT_EQ("100x100", std::get<0>(params).new_size.ToString()); // dip size | |
| 1457 EXPECT_EQ( | |
| 1458 "100x100", | |
| 1459 std::get<0>(params).physical_backing_size.ToString()); // backing size | |
| 1460 } | |
| 1461 } | 1451 } |
| 1462 | 1452 |
| 1463 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched | 1453 // Checks that InputMsg_CursorVisibilityChange IPC messages are dispatched |
| 1464 // to the renderer at the correct times. | 1454 // to the renderer at the correct times. |
| 1465 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) { | 1455 TEST_F(RenderWidgetHostViewAuraTest, CursorVisibilityChange) { |
| 1466 view_->InitAsChild(NULL); | 1456 view_->InitAsChild(NULL); |
| 1467 aura::client::ParentWindowWithContext( | 1457 aura::client::ParentWindowWithContext( |
| 1468 view_->GetNativeView(), | 1458 view_->GetNativeView(), |
| 1469 parent_view_->GetNativeView()->GetRootWindow(), | 1459 parent_view_->GetNativeView()->GetRootWindow(), |
| 1470 gfx::Rect()); | 1460 gfx::Rect()); |
| (...skipping 2823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4294 anchor_bound.set_type(gfx::SelectionBound::LEFT); | 4284 anchor_bound.set_type(gfx::SelectionBound::LEFT); |
| 4295 focus_bound.set_type(gfx::SelectionBound::RIGHT); | 4285 focus_bound.set_type(gfx::SelectionBound::RIGHT); |
| 4296 gfx::Rect measured_rect = | 4286 gfx::Rect measured_rect = |
| 4297 gfx::RectBetweenSelectionBounds(anchor_bound, focus_bound); | 4287 gfx::RectBetweenSelectionBounds(anchor_bound, focus_bound); |
| 4298 | 4288 |
| 4299 EXPECT_EQ(measured_rect, text_input_client()->GetCaretBounds()); | 4289 EXPECT_EQ(measured_rect, text_input_client()->GetCaretBounds()); |
| 4300 } | 4290 } |
| 4301 } | 4291 } |
| 4302 | 4292 |
| 4303 } // namespace content | 4293 } // namespace content |
| OLD | NEW |