Chromium Code Reviews| 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
| 6 | 6 |
| 7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1192 View* View::GetPreviousFocusableView() { | 1192 View* View::GetPreviousFocusableView() { |
| 1193 return previous_focusable_view_; | 1193 return previous_focusable_view_; |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 void View::SetNextFocusableView(View* view) { | 1196 void View::SetNextFocusableView(View* view) { |
| 1197 if (view) | 1197 if (view) |
| 1198 view->previous_focusable_view_ = this; | 1198 view->previous_focusable_view_ = this; |
| 1199 next_focusable_view_ = view; | 1199 next_focusable_view_ = view; |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 void View::SetFocusable(bool focusable) { | 1202 void View::SetFocusBehavior(FocusBehavior focus_behavior) { |
| 1203 if (focusable_ == focusable) | 1203 switch (focus_behavior) { |
|
tapted
2016/04/20 04:16:28
since SetFocusable/SetAccessibilityFocusable are b
karandeepb
2016/04/21 03:16:33
Yeah should have thought of this. Thanks.
| |
| 1204 return; | 1204 case FocusBehavior::ALWAYS: |
| 1205 | 1205 SetFocusable(true); |
| 1206 focusable_ = focusable; | 1206 SetAccessibilityFocusable(true); |
| 1207 AdvanceFocusIfNecessary(); | 1207 break; |
| 1208 case FocusBehavior::NEVER: | |
| 1209 SetFocusable(false); | |
| 1210 SetAccessibilityFocusable(false); | |
| 1211 break; | |
| 1212 case FocusBehavior::ACCESSIBLE_ONLY: | |
| 1213 SetFocusable(false); | |
| 1214 SetAccessibilityFocusable(true); | |
| 1215 break; | |
| 1216 } | |
| 1208 } | 1217 } |
| 1209 | 1218 |
| 1210 bool View::IsFocusable() const { | 1219 bool View::IsFocusable() const { |
| 1211 return focusable_ && enabled_ && IsDrawn(); | 1220 return focusable_ && enabled_ && IsDrawn(); |
| 1212 } | 1221 } |
| 1213 | 1222 |
| 1214 bool View::IsAccessibilityFocusable() const { | 1223 bool View::IsAccessibilityFocusable() const { |
| 1215 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); | 1224 return (focusable_ || accessibility_focusable_) && enabled_ && IsDrawn(); |
| 1216 } | 1225 } |
| 1217 | 1226 |
| 1218 void View::SetAccessibilityFocusable(bool accessibility_focusable) { | |
| 1219 if (accessibility_focusable_ == accessibility_focusable) | |
| 1220 return; | |
| 1221 | |
| 1222 accessibility_focusable_ = accessibility_focusable; | |
| 1223 AdvanceFocusIfNecessary(); | |
| 1224 } | |
| 1225 | |
| 1226 FocusManager* View::GetFocusManager() { | 1227 FocusManager* View::GetFocusManager() { |
| 1227 Widget* widget = GetWidget(); | 1228 Widget* widget = GetWidget(); |
| 1228 return widget ? widget->GetFocusManager() : NULL; | 1229 return widget ? widget->GetFocusManager() : NULL; |
| 1229 } | 1230 } |
| 1230 | 1231 |
| 1231 const FocusManager* View::GetFocusManager() const { | 1232 const FocusManager* View::GetFocusManager() const { |
| 1232 const Widget* widget = GetWidget(); | 1233 const Widget* widget = GetWidget(); |
| 1233 return widget ? widget->GetFocusManager() : NULL; | 1234 return widget ? widget->GetFocusManager() : NULL; |
| 1234 } | 1235 } |
| 1235 | 1236 |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2302 if (!leave_data_intact) { | 2303 if (!leave_data_intact) { |
| 2303 accelerators_->clear(); | 2304 accelerators_->clear(); |
| 2304 accelerators_.reset(); | 2305 accelerators_.reset(); |
| 2305 } | 2306 } |
| 2306 registered_accelerator_count_ = 0; | 2307 registered_accelerator_count_ = 0; |
| 2307 } | 2308 } |
| 2308 } | 2309 } |
| 2309 | 2310 |
| 2310 // Focus ----------------------------------------------------------------------- | 2311 // Focus ----------------------------------------------------------------------- |
| 2311 | 2312 |
| 2313 void View::SetFocusable(bool focusable) { | |
| 2314 if (focusable_ == focusable) | |
| 2315 return; | |
| 2316 | |
| 2317 focusable_ = focusable; | |
| 2318 AdvanceFocusIfNecessary(); | |
| 2319 } | |
| 2320 | |
| 2321 void View::SetAccessibilityFocusable(bool accessibility_focusable) { | |
| 2322 if (accessibility_focusable_ == accessibility_focusable) | |
| 2323 return; | |
| 2324 | |
| 2325 accessibility_focusable_ = accessibility_focusable; | |
| 2326 AdvanceFocusIfNecessary(); | |
| 2327 } | |
| 2328 | |
| 2312 void View::InitFocusSiblings(View* v, int index) { | 2329 void View::InitFocusSiblings(View* v, int index) { |
| 2313 int count = child_count(); | 2330 int count = child_count(); |
| 2314 | 2331 |
| 2315 if (count == 0) { | 2332 if (count == 0) { |
| 2316 v->next_focusable_view_ = NULL; | 2333 v->next_focusable_view_ = NULL; |
| 2317 v->previous_focusable_view_ = NULL; | 2334 v->previous_focusable_view_ = NULL; |
| 2318 } else { | 2335 } else { |
| 2319 if (index == count) { | 2336 if (index == count) { |
| 2320 // We are inserting at the end, but the end of the child list may not be | 2337 // We are inserting at the end, but the end of the child list may not be |
| 2321 // the last focusable element. Let's try to find an element with no next | 2338 // the last focusable element. Let's try to find an element with no next |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2424 // Message the RootView to do the drag and drop. That way if we're removed | 2441 // Message the RootView to do the drag and drop. That way if we're removed |
| 2425 // the RootView can detect it and avoid calling us back. | 2442 // the RootView can detect it and avoid calling us back. |
| 2426 gfx::Point widget_location(event.location()); | 2443 gfx::Point widget_location(event.location()); |
| 2427 ConvertPointToWidget(this, &widget_location); | 2444 ConvertPointToWidget(this, &widget_location); |
| 2428 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2445 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2429 // WARNING: we may have been deleted. | 2446 // WARNING: we may have been deleted. |
| 2430 return true; | 2447 return true; |
| 2431 } | 2448 } |
| 2432 | 2449 |
| 2433 } // namespace views | 2450 } // namespace views |
| OLD | NEW |