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(); } | 242 FocusBehavior focus_behavior() const { return View::focus_behavior(); } |
243 | 243 |
244 void set_can_process_events_within_subtree(bool can_process) { | 244 void set_can_process_events_within_subtree(bool can_process) { |
245 can_process_events_within_subtree_ = can_process; | 245 can_process_events_within_subtree_ = can_process; |
246 } | 246 } |
247 | 247 |
248 bool CanProcessEventsWithinSubtree() const override { | 248 bool CanProcessEventsWithinSubtree() const override { |
249 return can_process_events_within_subtree_; | 249 return can_process_events_within_subtree_; |
250 } | 250 } |
251 | 251 |
252 void Layout() override { | 252 void Layout() override { |
(...skipping 4106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4359 // Setting integral DSF should reset the offset. | 4359 // Setting integral DSF should reset the offset. |
4360 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); | 4360 GetRootLayer()->GetCompositor()->SetScaleAndSize(2.0f, size); |
4361 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); | 4361 EXPECT_EQ("0.00 0.00", ToString(v11->layer()->subpixel_position_offset())); |
4362 } | 4362 } |
4363 | 4363 |
4364 TEST_F(ViewTest, FocusableAssertions) { | 4364 TEST_F(ViewTest, FocusableAssertions) { |
4365 // View subclasses may change insets based on whether they are focusable, | 4365 // View subclasses may change insets based on whether they are focusable, |
4366 // which effects the preferred size. To avoid preferred size changing around | 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 | 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 | 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 | 4369 // that the return value of focus_behavior() depends on the last value passed |
4370 // SetFocusBehavior and not whether the View is focusable right now. | 4370 // to SetFocusBehavior and not whether the View is focusable right now. |
4371 TestView view; | 4371 TestView view; |
4372 view.SetFocusBehavior(View::FocusBehavior::ALWAYS); | 4372 view.SetFocusBehavior(View::FocusBehavior::ALWAYS); |
4373 EXPECT_TRUE(view.focusable()); | 4373 EXPECT_EQ(View::FocusBehavior::ALWAYS, view.focus_behavior()); |
4374 view.SetEnabled(false); | 4374 view.SetEnabled(false); |
4375 EXPECT_TRUE(view.focusable()); | 4375 EXPECT_EQ(View::FocusBehavior::ALWAYS, view.focus_behavior()); |
4376 view.SetFocusBehavior(View::FocusBehavior::NEVER); | 4376 view.SetFocusBehavior(View::FocusBehavior::NEVER); |
4377 EXPECT_FALSE(view.focusable()); | 4377 EXPECT_EQ(View::FocusBehavior::NEVER, view.focus_behavior()); |
| 4378 view.SetFocusBehavior(View::FocusBehavior::ACCESSIBLE_ONLY); |
| 4379 EXPECT_EQ(View::FocusBehavior::ACCESSIBLE_ONLY, view.focus_behavior()); |
4378 } | 4380 } |
4379 | 4381 |
4380 // Verifies when a view is deleted it is removed from ViewStorage. | 4382 // Verifies when a view is deleted it is removed from ViewStorage. |
4381 TEST_F(ViewTest, UpdateViewStorageOnDelete) { | 4383 TEST_F(ViewTest, UpdateViewStorageOnDelete) { |
4382 ViewStorage* view_storage = ViewStorage::GetInstance(); | 4384 ViewStorage* view_storage = ViewStorage::GetInstance(); |
4383 const int storage_id = view_storage->CreateStorageID(); | 4385 const int storage_id = view_storage->CreateStorageID(); |
4384 { | 4386 { |
4385 View view; | 4387 View view; |
4386 view_storage->StoreView(storage_id, &view); | 4388 view_storage->StoreView(storage_id, &view); |
4387 } | 4389 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4566 widget.Init(params); | 4568 widget.Init(params); |
4567 | 4569 |
4568 AddViewWithChildLayer(widget.GetRootView()); | 4570 AddViewWithChildLayer(widget.GetRootView()); |
4569 ViewThatAddsViewInOnNativeThemeChanged* v = | 4571 ViewThatAddsViewInOnNativeThemeChanged* v = |
4570 new ViewThatAddsViewInOnNativeThemeChanged; | 4572 new ViewThatAddsViewInOnNativeThemeChanged; |
4571 widget.GetRootView()->AddChildView(v); | 4573 widget.GetRootView()->AddChildView(v); |
4572 EXPECT_TRUE(v->on_native_theme_changed_called()); | 4574 EXPECT_TRUE(v->on_native_theme_changed_called()); |
4573 } | 4575 } |
4574 | 4576 |
4575 } // namespace views | 4577 } // namespace views |
OLD | NEW |