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 #ifndef UI_VIEWS_VIEW_H_ | 5 #ifndef UI_VIEWS_VIEW_H_ |
6 #define UI_VIEWS_VIEW_H_ | 6 #define UI_VIEWS_VIEW_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 // | 109 // |
110 ///////////////////////////////////////////////////////////////////////////// | 110 ///////////////////////////////////////////////////////////////////////////// |
111 class VIEWS_EXPORT View : public ui::LayerDelegate, | 111 class VIEWS_EXPORT View : public ui::LayerDelegate, |
112 public ui::LayerOwner, | 112 public ui::LayerOwner, |
113 public ui::AcceleratorTarget, | 113 public ui::AcceleratorTarget, |
114 public ui::EventTarget, | 114 public ui::EventTarget, |
115 public ui::EventHandler { | 115 public ui::EventHandler { |
116 public: | 116 public: |
117 typedef std::vector<View*> Views; | 117 typedef std::vector<View*> Views; |
118 | 118 |
119 enum class FocusBehavior { | |
sky
2016/04/18 15:40:24
Can you please separate out the FocusBehavior into
| |
120 // Use when the view is to be focusable both in default and full keyboard | |
121 // access mode. | |
122 ALWAYS, | |
123 | |
124 // Use when view is never focusable. Default. | |
125 NEVER, | |
126 | |
127 // Use when the view is to be made focusable only during full keyboard mode. | |
128 ACCESSIBLE_ONLY, | |
129 }; | |
130 | |
119 struct ViewHierarchyChangedDetails { | 131 struct ViewHierarchyChangedDetails { |
120 ViewHierarchyChangedDetails() | 132 ViewHierarchyChangedDetails() |
121 : is_add(false), | 133 : is_add(false), |
122 parent(NULL), | 134 parent(NULL), |
123 child(NULL), | 135 child(NULL), |
124 move_view(NULL) {} | 136 move_view(NULL) {} |
125 | 137 |
126 ViewHierarchyChangedDetails(bool is_add, | 138 ViewHierarchyChangedDetails(bool is_add, |
127 View* parent, | 139 View* parent, |
128 View* child, | 140 View* child, |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 // Returns the view that should be selected next when pressing Shift-Tab. | 772 // Returns the view that should be selected next when pressing Shift-Tab. |
761 View* GetPreviousFocusableView(); | 773 View* GetPreviousFocusableView(); |
762 | 774 |
763 // Sets the component that should be selected next when pressing Tab, and | 775 // Sets the component that should be selected next when pressing Tab, and |
764 // makes the current view the precedent view of the specified one. | 776 // makes the current view the precedent view of the specified one. |
765 // Note that by default views are linked in the order they have been added to | 777 // Note that by default views are linked in the order they have been added to |
766 // their container. Use this method if you want to modify the order. | 778 // their container. Use this method if you want to modify the order. |
767 // IMPORTANT NOTE: loops in the focus hierarchy are not supported. | 779 // IMPORTANT NOTE: loops in the focus hierarchy are not supported. |
768 void SetNextFocusableView(View* view); | 780 void SetNextFocusableView(View* view); |
769 | 781 |
770 // Sets whether this view is capable of taking focus. It will clear focus if | 782 // Sets |focusable_| and |accessibility_focusable_| corresponding to the given |
771 // the focused view is set to be non-focusable. | 783 // |focus_behavior|. |
772 // Note that this is false by default so that a view used as a container does | 784 void SetFocusBehavior(FocusBehavior focus_behavior); |
773 // not get the focus. | |
774 void SetFocusable(bool focusable); | |
775 | 785 |
776 // Returns true if this view is |focusable_|, |enabled_| and drawn. | 786 // Returns true if this view is |focusable_|, |enabled_| and drawn. |
777 bool IsFocusable() const; | 787 bool IsFocusable() const; |
778 | 788 |
779 // Return whether this view is focusable when the user requires full keyboard | 789 // Return whether this view is focusable when the user requires full keyboard |
780 // access, even though it may not be normally focusable. | 790 // access, even though it may not be normally focusable. |
781 bool IsAccessibilityFocusable() const; | 791 bool IsAccessibilityFocusable() const; |
782 | 792 |
783 // Set whether this view can be made focusable if the user requires | |
784 // full keyboard access, even though it's not normally focusable. It will | |
785 // clear focus if the focused view is set to be non-focusable. | |
786 // Note that this is false by default. | |
787 void SetAccessibilityFocusable(bool accessibility_focusable); | |
788 | |
789 // Convenience method to retrieve the FocusManager associated with the | 793 // Convenience method to retrieve the FocusManager associated with the |
790 // Widget that contains this view. This can return NULL if this view is not | 794 // Widget that contains this view. This can return NULL if this view is not |
791 // part of a view hierarchy with a Widget. | 795 // part of a view hierarchy with a Widget. |
792 virtual FocusManager* GetFocusManager(); | 796 virtual FocusManager* GetFocusManager(); |
793 virtual const FocusManager* GetFocusManager() const; | 797 virtual const FocusManager* GetFocusManager() const; |
794 | 798 |
795 // Request keyboard focus. The receiving view will become the focused view. | 799 // Request keyboard focus. The receiving view will become the focused view. |
796 virtual void RequestFocus(); | 800 virtual void RequestFocus(); |
797 | 801 |
798 // Invoked when a view is about to be requested for focus due to the focus | 802 // Invoked when a view is about to be requested for focus due to the focus |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1138 // Input --------------------------------------------------------------------- | 1142 // Input --------------------------------------------------------------------- |
1139 | 1143 |
1140 virtual DragInfo* GetDragInfo(); | 1144 virtual DragInfo* GetDragInfo(); |
1141 | 1145 |
1142 // Focus --------------------------------------------------------------------- | 1146 // Focus --------------------------------------------------------------------- |
1143 | 1147 |
1144 // Returns last value passed to SetFocusable(). Use IsFocusable() to determine | 1148 // Returns last value passed to SetFocusable(). Use IsFocusable() to determine |
1145 // if a view can take focus right now. | 1149 // if a view can take focus right now. |
1146 bool focusable() const { return focusable_; } | 1150 bool focusable() const { return focusable_; } |
1147 | 1151 |
1152 // Returns last value passed to SetAccessibilityFocusable(). Use | |
1153 // IsAccessibilityFocusable() to determine if a view can take focus right now | |
1154 // in accessibility mode. | |
1155 bool accessibility_focusable() const { return accessibility_focusable_; } | |
1156 | |
1148 // Override to be notified when focus has changed either to or from this View. | 1157 // Override to be notified when focus has changed either to or from this View. |
1149 virtual void OnFocus(); | 1158 virtual void OnFocus(); |
1150 virtual void OnBlur(); | 1159 virtual void OnBlur(); |
1151 | 1160 |
1152 // Handle view focus/blur events for this view. | 1161 // Handle view focus/blur events for this view. |
1153 void Focus(); | 1162 void Focus(); |
1154 void Blur(); | 1163 void Blur(); |
1155 | 1164 |
1156 // System events ------------------------------------------------------------- | 1165 // System events ------------------------------------------------------------- |
1157 | 1166 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1377 // FocusManager yet, if possible. | 1386 // FocusManager yet, if possible. |
1378 void RegisterPendingAccelerators(); | 1387 void RegisterPendingAccelerators(); |
1379 | 1388 |
1380 // Unregisters all the keyboard accelerators associated with this view. | 1389 // Unregisters all the keyboard accelerators associated with this view. |
1381 // |leave_data_intact| if true does not remove data from accelerators_ array, | 1390 // |leave_data_intact| if true does not remove data from accelerators_ array, |
1382 // so it could be re-registered with other focus manager | 1391 // so it could be re-registered with other focus manager |
1383 void UnregisterAccelerators(bool leave_data_intact); | 1392 void UnregisterAccelerators(bool leave_data_intact); |
1384 | 1393 |
1385 // Focus --------------------------------------------------------------------- | 1394 // Focus --------------------------------------------------------------------- |
1386 | 1395 |
1396 // Helper method for SetFocusBehavior(..). | |
1397 // Sets whether this view is capable of taking focus. It will clear focus if | |
1398 // the focused view is set to be non-focusable. | |
1399 // Note that this is false by default so that a view used as a container does | |
1400 // not get the focus. | |
1401 void SetFocusable(bool focusable); | |
1402 | |
1403 // Helper method for SetFocusBehavior(..). | |
1404 // Set whether this view can be made focusable if the user requires | |
1405 // full keyboard access, even though it's not normally focusable. It will | |
1406 // clear focus if the focused view is set to be non-focusable. | |
1407 // Note that this is false by default. | |
1408 void SetAccessibilityFocusable(bool accessibility_focusable); | |
1409 | |
1387 // Initialize the previous/next focusable views of the specified view relative | 1410 // Initialize the previous/next focusable views of the specified view relative |
1388 // to the view at the specified index. | 1411 // to the view at the specified index. |
1389 void InitFocusSiblings(View* view, int index); | 1412 void InitFocusSiblings(View* view, int index); |
1390 | 1413 |
1391 // Helper function to advance focus, in case the currently focused view has | 1414 // Helper function to advance focus, in case the currently focused view has |
1392 // become unfocusable. | 1415 // become unfocusable. |
1393 void AdvanceFocusIfNecessary(); | 1416 void AdvanceFocusIfNecessary(); |
1394 | 1417 |
1395 // System events ------------------------------------------------------------- | 1418 // System events ------------------------------------------------------------- |
1396 | 1419 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1569 // Belongs to this view, but it's reference-counted on some platforms | 1592 // Belongs to this view, but it's reference-counted on some platforms |
1570 // so we can't use a scoped_ptr. It's dereferenced in the destructor. | 1593 // so we can't use a scoped_ptr. It's dereferenced in the destructor. |
1571 NativeViewAccessibility* native_view_accessibility_; | 1594 NativeViewAccessibility* native_view_accessibility_; |
1572 | 1595 |
1573 DISALLOW_COPY_AND_ASSIGN(View); | 1596 DISALLOW_COPY_AND_ASSIGN(View); |
1574 }; | 1597 }; |
1575 | 1598 |
1576 } // namespace views | 1599 } // namespace views |
1577 | 1600 |
1578 #endif // UI_VIEWS_VIEW_H_ | 1601 #endif // UI_VIEWS_VIEW_H_ |
OLD | NEW |