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/view.h" | 5 #include "ui/views/view.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 // Exposed as public for testing. | 233 // Exposed as public for testing. |
234 void DoFocus() { | 234 void DoFocus() { |
235 views::View::Focus(); | 235 views::View::Focus(); |
236 } | 236 } |
237 | 237 |
238 void DoBlur() { | 238 void DoBlur() { |
239 views::View::Blur(); | 239 views::View::Blur(); |
240 } | 240 } |
241 | 241 |
242 bool focusable() const { return View::focusable(); } | |
243 | |
244 void set_can_process_events_within_subtree(bool can_process) { | 242 void set_can_process_events_within_subtree(bool can_process) { |
245 can_process_events_within_subtree_ = can_process; | 243 can_process_events_within_subtree_ = can_process; |
246 } | 244 } |
247 | 245 |
248 bool CanProcessEventsWithinSubtree() const override { | 246 bool CanProcessEventsWithinSubtree() const override { |
249 return can_process_events_within_subtree_; | 247 return can_process_events_within_subtree_; |
250 } | 248 } |
251 | 249 |
252 void Layout() override { | 250 void Layout() override { |
253 did_layout_ = true; | 251 did_layout_ = true; |
(...skipping 4100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4354 | 4352 |
4355 // Setting parent view should update the child view's layer's offset. | 4353 // Setting parent view should update the child view's layer's offset. |
4356 v1->SetBoundsRect(gfx::Rect(2, 2, 10, 10)); | 4354 v1->SetBoundsRect(gfx::Rect(2, 2, 10, 10)); |
4357 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); | 4355 EXPECT_EQ("0.33 0.33", ToString(v11->layer()->subpixel_position_offset())); |
4358 | 4356 |
4359 // Setting integral DSF should reset the offset. | 4357 // Setting integral DSF should reset the offset. |
4360 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); | 4358 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); |
4361 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); | 4359 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); |
4362 } | 4360 } |
4363 | 4361 |
4364 TEST_F(ViewTest, FocusableAssertions) { | |
4365 // View subclasses may change insets based on whether they are focusable, | |
4366 // which effects the preferred size. To avoid preferred size changing around | |
4367 // these Views need to key off the last value set to SetFocusBehavior(), not | |
4368 // whether the View is focusable right now. For this reason it's important | |
4369 // that the return value of focusable() depends on the last value passed to | |
4370 // SetFocusBehavior and not whether the View is focusable right now. | |
4371 TestView view; | |
4372 view.SetFocusBehavior(View::FocusBehavior::ALWAYS); | |
4373 EXPECT_TRUE(view.focusable()); | |
4374 view.SetEnabled(false); | |
4375 EXPECT_TRUE(view.focusable()); | |
4376 view.SetFocusBehavior(View::FocusBehavior::NEVER); | |
4377 EXPECT_FALSE(view.focusable()); | |
4378 } | |
4379 | |
4380 // Verifies when a view is deleted it is removed from ViewStorage. | 4362 // Verifies when a view is deleted it is removed from ViewStorage. |
4381 TEST_F(ViewTest, UpdateViewStorageOnDelete) { | 4363 TEST_F(ViewTest, UpdateViewStorageOnDelete) { |
4382 ViewStorage* view_storage = ViewStorage::GetInstance(); | 4364 ViewStorage* view_storage = ViewStorage::GetInstance(); |
4383 const int storage_id = view_storage->CreateStorageID(); | 4365 const int storage_id = view_storage->CreateStorageID(); |
4384 { | 4366 { |
4385 View view; | 4367 View view; |
4386 view_storage->StoreView(storage_id, &view); | 4368 view_storage->StoreView(storage_id, &view); |
4387 } | 4369 } |
4388 EXPECT_TRUE(view_storage->RetrieveView(storage_id) == NULL); | 4370 EXPECT_TRUE(view_storage->RetrieveView(storage_id) == NULL); |
4389 } | 4371 } |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4566 widget.Init(params); | 4548 widget.Init(params); |
4567 | 4549 |
4568 AddViewWithChildLayer(widget.GetRootView()); | 4550 AddViewWithChildLayer(widget.GetRootView()); |
4569 ViewThatAddsViewInOnNativeThemeChanged* v = | 4551 ViewThatAddsViewInOnNativeThemeChanged* v = |
4570 new ViewThatAddsViewInOnNativeThemeChanged; | 4552 new ViewThatAddsViewInOnNativeThemeChanged; |
4571 widget.GetRootView()->AddChildView(v); | 4553 widget.GetRootView()->AddChildView(v); |
4572 EXPECT_TRUE(v->on_native_theme_changed_called()); | 4554 EXPECT_TRUE(v->on_native_theme_changed_called()); |
4573 } | 4555 } |
4574 | 4556 |
4575 } // namespace views | 4557 } // namespace views |
OLD | NEW |