| 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 "ui/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 parent->SetBounds(gfx::Rect(20, 40, 480, 320)); | 93 parent->SetBounds(gfx::Rect(20, 40, 480, 320)); |
| 94 scoped_ptr<Widget> widget(new Widget()); | 94 scoped_ptr<Widget> widget(new Widget()); |
| 95 NativeWidgetAura* window = Init(parent.get(), widget.get()); | 95 NativeWidgetAura* window = Init(parent.get(), widget.get()); |
| 96 window->CenterWindow(gfx::Size(500, 600)); | 96 window->CenterWindow(gfx::Size(500, 600)); |
| 97 | 97 |
| 98 // |window| should be no bigger than |parent|. | 98 // |window| should be no bigger than |parent|. |
| 99 EXPECT_EQ("20,40 480x320", window->GetNativeWindow()->bounds().ToString()); | 99 EXPECT_EQ("20,40 480x320", window->GetNativeWindow()->bounds().ToString()); |
| 100 widget->CloseNow(); | 100 widget->CloseNow(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 class TestLayoutManagerBase : public aura::LayoutManager { |
| 104 public: |
| 105 TestLayoutManagerBase() {} |
| 106 virtual ~TestLayoutManagerBase() {} |
| 107 |
| 108 // aura::LayoutManager: |
| 109 virtual void OnWindowResized() OVERRIDE {} |
| 110 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {} |
| 111 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 112 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
| 113 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 114 bool visible) OVERRIDE {} |
| 115 virtual void SetChildBounds(aura::Window* child, |
| 116 const gfx::Rect& requested_bounds) OVERRIDE {} |
| 117 |
| 118 private: |
| 119 DISALLOW_COPY_AND_ASSIGN(TestLayoutManagerBase); |
| 120 }; |
| 121 |
| 103 // Used by ShowMaximizedDoesntBounceAround. See it for details. | 122 // Used by ShowMaximizedDoesntBounceAround. See it for details. |
| 104 class TestLayoutManager : public aura::LayoutManager { | 123 class MaximizeLayoutManager : public TestLayoutManagerBase { |
| 105 public: | 124 public: |
| 106 TestLayoutManager() {} | 125 MaximizeLayoutManager() {} |
| 126 virtual ~MaximizeLayoutManager() {} |
| 107 | 127 |
| 108 virtual void OnWindowResized() OVERRIDE { | 128 private: |
| 109 } | 129 // aura::LayoutManager: |
| 110 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { | 130 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| 111 // This simulates what happens when adding a maximized window. | 131 // This simulates what happens when adding a maximized window. |
| 112 SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300)); | 132 SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300)); |
| 113 } | 133 } |
| 114 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { | |
| 115 } | |
| 116 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | |
| 117 } | |
| 118 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | |
| 119 bool visible) OVERRIDE { | |
| 120 } | |
| 121 virtual void SetChildBounds(aura::Window* child, | |
| 122 const gfx::Rect& requested_bounds) OVERRIDE { | |
| 123 } | |
| 124 | 134 |
| 125 private: | 135 DISALLOW_COPY_AND_ASSIGN(MaximizeLayoutManager); |
| 126 DISALLOW_COPY_AND_ASSIGN(TestLayoutManager); | |
| 127 }; | 136 }; |
| 128 | 137 |
| 129 // This simulates BrowserView, which creates a custom RootView so that | 138 // This simulates BrowserView, which creates a custom RootView so that |
| 130 // OnNativeWidgetSizeChanged that is invoked during Init matters. | 139 // OnNativeWidgetSizeChanged that is invoked during Init matters. |
| 131 class TestWidget : public views::Widget { | 140 class TestWidget : public views::Widget { |
| 132 public: | 141 public: |
| 133 TestWidget() : did_size_change_more_than_once_(false) { | 142 TestWidget() : did_size_change_more_than_once_(false) { |
| 134 } | 143 } |
| 135 | 144 |
| 136 // Returns true if the size changes to a non-empty size, and then to another | 145 // Returns true if the size changes to a non-empty size, and then to another |
| (...skipping 16 matching lines...) Expand all Loading... |
| 153 | 162 |
| 154 DISALLOW_COPY_AND_ASSIGN(TestWidget); | 163 DISALLOW_COPY_AND_ASSIGN(TestWidget); |
| 155 }; | 164 }; |
| 156 | 165 |
| 157 // Verifies the size of the widget doesn't change more than once during Init if | 166 // Verifies the size of the widget doesn't change more than once during Init if |
| 158 // the window ends up maximized. This is important as otherwise | 167 // the window ends up maximized. This is important as otherwise |
| 159 // RenderWidgetHostViewAura ends up getting resized during construction, which | 168 // RenderWidgetHostViewAura ends up getting resized during construction, which |
| 160 // leads to noticable flashes. | 169 // leads to noticable flashes. |
| 161 TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) { | 170 TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) { |
| 162 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); | 171 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); |
| 163 root_window()->SetLayoutManager(new TestLayoutManager); | 172 root_window()->SetLayoutManager(new MaximizeLayoutManager); |
| 164 scoped_ptr<TestWidget> widget(new TestWidget()); | 173 scoped_ptr<TestWidget> widget(new TestWidget()); |
| 165 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 174 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 166 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 175 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 167 params.parent = NULL; | 176 params.parent = NULL; |
| 168 params.context = root_window(); | 177 params.context = root_window(); |
| 169 params.show_state = ui::SHOW_STATE_MAXIMIZED; | 178 params.show_state = ui::SHOW_STATE_MAXIMIZED; |
| 170 params.bounds = gfx::Rect(10, 10, 100, 200); | 179 params.bounds = gfx::Rect(10, 10, 100, 200); |
| 171 widget->Init(params); | 180 widget->Init(params); |
| 172 EXPECT_FALSE(widget->did_size_change_more_than_once()); | 181 EXPECT_FALSE(widget->did_size_change_more_than_once()); |
| 173 widget->CloseNow(); | 182 widget->CloseNow(); |
| 174 } | 183 } |
| 175 | 184 |
| 185 class PropertyTestLayoutManager : public TestLayoutManagerBase { |
| 186 public: |
| 187 PropertyTestLayoutManager() : added_(false) {} |
| 188 virtual ~PropertyTestLayoutManager() {} |
| 189 |
| 190 bool added() const { return added_; } |
| 191 |
| 192 private: |
| 193 // aura::LayoutManager: |
| 194 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| 195 EXPECT_TRUE(child->GetProperty(aura::client::kCanMaximizeKey)); |
| 196 EXPECT_TRUE(child->GetProperty(aura::client::kCanResizeKey)); |
| 197 added_ = true; |
| 198 } |
| 199 |
| 200 bool added_; |
| 201 |
| 202 DISALLOW_COPY_AND_ASSIGN(PropertyTestLayoutManager); |
| 203 }; |
| 204 |
| 205 class PropertyTestWidgetDelegate : public views::WidgetDelegate { |
| 206 public: |
| 207 explicit PropertyTestWidgetDelegate(Widget* widget) : widget_(widget) {} |
| 208 virtual ~PropertyTestWidgetDelegate() {} |
| 209 |
| 210 private: |
| 211 // views::WidgetDelegate: |
| 212 virtual bool CanMaximize() const OVERRIDE { |
| 213 return true; |
| 214 } |
| 215 virtual bool CanResize() const OVERRIDE { |
| 216 return true; |
| 217 } |
| 218 virtual void DeleteDelegate() OVERRIDE { |
| 219 delete this; |
| 220 } |
| 221 virtual Widget* GetWidget() OVERRIDE { |
| 222 return widget_; |
| 223 } |
| 224 virtual const Widget* GetWidget() const OVERRIDE { |
| 225 return widget_; |
| 226 } |
| 227 |
| 228 Widget* widget_; |
| 229 DISALLOW_COPY_AND_ASSIGN(PropertyTestWidgetDelegate); |
| 230 }; |
| 231 |
| 232 // Verifies that the kCanMaximizeKey/kCanReizeKey have the correct |
| 233 // value when added to the layout manager. |
| 234 TEST_F(NativeWidgetAuraTest, TestPropertiesWhenAddedToLayout) { |
| 235 root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); |
| 236 PropertyTestLayoutManager* layout_manager = new PropertyTestLayoutManager(); |
| 237 root_window()->SetLayoutManager(layout_manager); |
| 238 scoped_ptr<TestWidget> widget(new TestWidget()); |
| 239 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 240 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 241 params.delegate = new PropertyTestWidgetDelegate(widget.get()); |
| 242 params.parent = NULL; |
| 243 params.context = root_window(); |
| 244 widget->Init(params); |
| 245 EXPECT_TRUE(layout_manager->added()); |
| 246 widget->CloseNow(); |
| 247 } |
| 248 |
| 176 TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) { | 249 TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) { |
| 177 // Create a widget. | 250 // Create a widget. |
| 178 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 251 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
| 179 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 252 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 180 params.context = root_window(); | 253 params.context = root_window(); |
| 181 params.bounds.SetRect(10, 20, 300, 400); | 254 params.bounds.SetRect(10, 20, 300, 400); |
| 182 scoped_ptr<Widget> widget(new Widget()); | 255 scoped_ptr<Widget> widget(new Widget()); |
| 183 widget->Init(params); | 256 widget->Init(params); |
| 184 | 257 |
| 185 // For Aura, client area bounds match window bounds. | 258 // For Aura, client area bounds match window bounds. |
| 186 gfx::Rect client_bounds = widget->GetClientAreaBoundsInScreen(); | 259 gfx::Rect client_bounds = widget->GetClientAreaBoundsInScreen(); |
| 187 EXPECT_EQ(10, client_bounds.x()); | 260 EXPECT_EQ(10, client_bounds.x()); |
| 188 EXPECT_EQ(20, client_bounds.y()); | 261 EXPECT_EQ(20, client_bounds.y()); |
| 189 EXPECT_EQ(300, client_bounds.width()); | 262 EXPECT_EQ(300, client_bounds.width()); |
| 190 EXPECT_EQ(400, client_bounds.height()); | 263 EXPECT_EQ(400, client_bounds.height()); |
| 191 } | 264 } |
| 192 | 265 |
| 193 namespace { | |
| 194 | |
| 195 // View subclass that tracks whether it has gotten a gesture event. | 266 // View subclass that tracks whether it has gotten a gesture event. |
| 196 class GestureTrackingView : public views::View { | 267 class GestureTrackingView : public views::View { |
| 197 public: | 268 public: |
| 198 GestureTrackingView() | 269 GestureTrackingView() |
| 199 : got_gesture_event_(false), | 270 : got_gesture_event_(false), |
| 200 consume_gesture_event_(true) {} | 271 consume_gesture_event_(true) {} |
| 201 | 272 |
| 202 void set_consume_gesture_event(bool value) { | 273 void set_consume_gesture_event(bool value) { |
| 203 consume_gesture_event_ = value; | 274 consume_gesture_event_ = value; |
| 204 } | 275 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 220 private: | 291 private: |
| 221 // Was OnGestureEvent() invoked? | 292 // Was OnGestureEvent() invoked? |
| 222 bool got_gesture_event_; | 293 bool got_gesture_event_; |
| 223 | 294 |
| 224 // Dictates what OnGestureEvent() returns. | 295 // Dictates what OnGestureEvent() returns. |
| 225 bool consume_gesture_event_; | 296 bool consume_gesture_event_; |
| 226 | 297 |
| 227 DISALLOW_COPY_AND_ASSIGN(GestureTrackingView); | 298 DISALLOW_COPY_AND_ASSIGN(GestureTrackingView); |
| 228 }; | 299 }; |
| 229 | 300 |
| 230 } // namespace | |
| 231 | |
| 232 // Verifies a capture isn't set on touch press and that the view that gets | 301 // Verifies a capture isn't set on touch press and that the view that gets |
| 233 // the press gets the release. | 302 // the press gets the release. |
| 234 TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) { | 303 TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) { |
| 235 // Create two views (both sized the same). |child| is configured not to | 304 // Create two views (both sized the same). |child| is configured not to |
| 236 // consume the gesture event. | 305 // consume the gesture event. |
| 237 GestureTrackingView* view = new GestureTrackingView(); | 306 GestureTrackingView* view = new GestureTrackingView(); |
| 238 GestureTrackingView* child = new GestureTrackingView(); | 307 GestureTrackingView* child = new GestureTrackingView(); |
| 239 child->set_consume_gesture_event(false); | 308 child->set_consume_gesture_event(false); |
| 240 view->SetLayoutManager(new FillLayout); | 309 view->SetLayoutManager(new FillLayout); |
| 241 view->AddChildView(child); | 310 view->AddChildView(child); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 delegate->ClearGotMove(); | 473 delegate->ClearGotMove(); |
| 405 // Simulate a maximize with animation. | 474 // Simulate a maximize with animation. |
| 406 delete widget->GetNativeView()->RecreateLayer().release(); | 475 delete widget->GetNativeView()->RecreateLayer().release(); |
| 407 widget->SetBounds(gfx::Rect(0, 0, 500, 500)); | 476 widget->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 408 EXPECT_TRUE(delegate->got_move()); | 477 EXPECT_TRUE(delegate->got_move()); |
| 409 widget->CloseNow(); | 478 widget->CloseNow(); |
| 410 } | 479 } |
| 411 | 480 |
| 412 } // namespace | 481 } // namespace |
| 413 } // namespace views | 482 } // namespace views |
| OLD | NEW |