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