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 { | |
120 // Use when the view is never focusable. Default. | |
tapted
2016/04/21 05:33:06
nit: view->View (2 others below)
karandeepb
2016/04/21 10:33:33
Done.
| |
121 NEVER, | |
122 | |
123 // Use when the view is to be focusable both in regular and accessibility | |
124 // mode. | |
125 ALWAYS, | |
126 | |
127 // Use when the view is focusable only during accessibility 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 |focus_behavior_| as per the passed value. Advances focus if |
tapted
2016/04/21 05:33:06
nit: I think it's enough just to say
// Sets |foc
karandeepb
2016/04/21 10:33:33
Done.
| |
771 // the focused view is set to be non-focusable. | 783 // necessary. |
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 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 // with an associated view. Widget::ReorderNativeViews() may reorder layers | 1138 // with an associated view. Widget::ReorderNativeViews() may reorder layers |
1135 // below layers owned by a view. | 1139 // below layers owned by a view. |
1136 virtual void ReorderChildLayers(ui::Layer* parent_layer); | 1140 virtual void ReorderChildLayers(ui::Layer* parent_layer); |
1137 | 1141 |
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 true if ALWAYS is the last set focus behavior. Use IsFocusable() to |
1145 // if a view can take focus right now. | 1149 // determine if a view can take focus right now. |
1146 bool focusable() const { return focusable_; } | 1150 bool focusable() const { return focus_behavior_ == FocusBehavior::ALWAYS; } |
tapted
2016/04/21 05:33:07
Maybe we want to rename this now to CanFocus? (or
karandeepb
2016/04/21 10:33:33
Will do this in https://codereview.chromium.org/18
| |
1147 | 1151 |
1148 // Override to be notified when focus has changed either to or from this View. | 1152 // Override to be notified when focus has changed either to or from this View. |
1149 virtual void OnFocus(); | 1153 virtual void OnFocus(); |
1150 virtual void OnBlur(); | 1154 virtual void OnBlur(); |
1151 | 1155 |
1152 // Handle view focus/blur events for this view. | 1156 // Handle view focus/blur events for this view. |
1153 void Focus(); | 1157 void Focus(); |
1154 void Blur(); | 1158 void Blur(); |
1155 | 1159 |
1156 // System events ------------------------------------------------------------- | 1160 // System events ------------------------------------------------------------- |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1537 size_t registered_accelerator_count_; | 1541 size_t registered_accelerator_count_; |
1538 | 1542 |
1539 // Focus --------------------------------------------------------------------- | 1543 // Focus --------------------------------------------------------------------- |
1540 | 1544 |
1541 // Next view to be focused when the Tab key is pressed. | 1545 // Next view to be focused when the Tab key is pressed. |
1542 View* next_focusable_view_; | 1546 View* next_focusable_view_; |
1543 | 1547 |
1544 // Next view to be focused when the Shift-Tab key combination is pressed. | 1548 // Next view to be focused when the Shift-Tab key combination is pressed. |
1545 View* previous_focusable_view_; | 1549 View* previous_focusable_view_; |
1546 | 1550 |
1547 // Whether this view can be focused. | 1551 // The focus behavior of the view in regular and accessibility mode. |
1548 bool focusable_; | 1552 FocusBehavior focus_behavior_; |
1549 | |
1550 // Whether this view is focusable if the user requires full keyboard access, | |
1551 // even though it may not be normally focusable. | |
1552 bool accessibility_focusable_; | |
1553 | 1553 |
1554 // Context menus ------------------------------------------------------------- | 1554 // Context menus ------------------------------------------------------------- |
1555 | 1555 |
1556 // The menu controller. | 1556 // The menu controller. |
1557 ContextMenuController* context_menu_controller_; | 1557 ContextMenuController* context_menu_controller_; |
1558 | 1558 |
1559 // Drag and drop ------------------------------------------------------------- | 1559 // Drag and drop ------------------------------------------------------------- |
1560 | 1560 |
1561 DragController* drag_controller_; | 1561 DragController* drag_controller_; |
1562 | 1562 |
1563 // Input -------------------------------------------------------------------- | 1563 // Input -------------------------------------------------------------------- |
1564 | 1564 |
1565 std::unique_ptr<ViewTargeter> targeter_; | 1565 std::unique_ptr<ViewTargeter> targeter_; |
1566 | 1566 |
1567 // Accessibility ------------------------------------------------------------- | 1567 // Accessibility ------------------------------------------------------------- |
1568 | 1568 |
1569 // Belongs to this view, but it's reference-counted on some platforms | 1569 // 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. | 1570 // so we can't use a scoped_ptr. It's dereferenced in the destructor. |
1571 NativeViewAccessibility* native_view_accessibility_; | 1571 NativeViewAccessibility* native_view_accessibility_; |
1572 | 1572 |
1573 DISALLOW_COPY_AND_ASSIGN(View); | 1573 DISALLOW_COPY_AND_ASSIGN(View); |
1574 }; | 1574 }; |
1575 | 1575 |
1576 } // namespace views | 1576 } // namespace views |
1577 | 1577 |
1578 #endif // UI_VIEWS_VIEW_H_ | 1578 #endif // UI_VIEWS_VIEW_H_ |
OLD | NEW |