Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: ui/views/controls/tabbed_pane/tabbed_pane.h

Issue 2368283002: views: add focus to TabbedPane (Closed)
Patch Set: rename some stuff, move Tab class Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/views/controls/tabbed_pane/tabbed_pane.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_CONTROLS_TABBED_PANE_TABBED_PANE_H_ 5 #ifndef UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_
6 #define UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_ 6 #define UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "ui/views/view.h" 11 #include "ui/views/view.h"
12 12
13 namespace views { 13 namespace views {
14 14
15 class Label;
15 class Tab; 16 class Tab;
16 class TabbedPaneListener; 17 class TabbedPaneListener;
17 class TabStrip; 18 class TabStrip;
18 19
19 // TabbedPane is a view that shows tabs. When the user clicks on a tab, the 20 // TabbedPane is a view that shows tabs. When the user clicks on a tab, the
20 // associated view is displayed. 21 // associated view is displayed.
21 class VIEWS_EXPORT TabbedPane : public View { 22 class VIEWS_EXPORT TabbedPane : public View {
22 public: 23 public:
23 // Internal class name. 24 // Internal class name.
24 static const char kViewClassName[]; 25 static const char kViewClassName[];
25 26
26 TabbedPane(); 27 TabbedPane();
27 ~TabbedPane() override; 28 ~TabbedPane() override;
28 29
29 TabbedPaneListener* listener() const { return listener_; } 30 TabbedPaneListener* listener() const { return listener_; }
30 void set_listener(TabbedPaneListener* listener) { listener_ = listener; } 31 void set_listener(TabbedPaneListener* listener) { listener_ = listener; }
31 32
32 int selected_tab_index() const { return selected_tab_index_; } 33 int selected_tab_index() const { return selected_tab_index_; }
33 34
34 // Returns the number of tabs. 35 // Returns the number of tabs.
35 int GetTabCount(); 36 int GetTabCount();
36 37
37 // Returns the contents of the selected tab or NULL if there is none.
38 View* GetSelectedTab();
39
40 // Adds a new tab at the end of this TabbedPane with the specified |title|. 38 // Adds a new tab at the end of this TabbedPane with the specified |title|.
41 // |contents| is the view displayed when the tab is selected and is owned by 39 // |contents| is the view displayed when the tab is selected and is owned by
42 // the TabbedPane. 40 // the TabbedPane.
43 void AddTab(const base::string16& title, View* contents); 41 void AddTab(const base::string16& title, View* contents);
44 42
45 // Adds a new tab at |index| with |title|. |contents| is the view displayed 43 // Adds a new tab at |index| with |title|. |contents| is the view displayed
46 // when the tab is selected and is owned by the TabbedPane. If the tabbed pane 44 // when the tab is selected and is owned by the TabbedPane. If the tabbed pane
47 // is currently empty, the new tab is selected. 45 // is currently empty, the new tab is selected.
48 void AddTabAtIndex(int index, const base::string16& title, View* contents); 46 void AddTabAtIndex(int index, const base::string16& title, View* contents);
49 47
50 // Selects the tab at |index|, which must be valid. 48 // Selects the tab at |index|, which must be valid.
51 void SelectTabAt(int index); 49 void SelectTabAt(int index);
52 50
53 // Selects |tab| (the tabstrip view, not its content) if it is valid. 51 // Selects |tab| (the tabstrip view, not its content) if it is valid.
54 void SelectTab(Tab* tab); 52 void SelectTab(Tab* tab);
55 53
56 // Overridden from View: 54 // Overridden from View:
57 gfx::Size GetPreferredSize() const override; 55 gfx::Size GetPreferredSize() const override;
58 const char* GetClassName() const override; 56 const char* GetClassName() const override;
59 57
60 private: 58 private:
59 friend class FocusTraversalTest;
60 friend class Tab;
61 friend class TabStrip; 61 friend class TabStrip;
62 FRIEND_TEST_ALL_PREFIXES(TabbedPaneTest, AddAndSelect);
63 FRIEND_TEST_ALL_PREFIXES(TabbedPaneTest, ArrowKeyBindings);
62 64
63 // Get the Tab (the tabstrip view, not its content) at the valid |index|. 65 // Get the Tab (the tabstrip view, not its content) at the valid |index|.
64 Tab* GetTabAt(int index); 66 Tab* GetTabAt(int index);
65 67
68 // Get the Tab (the tabstrip view, not its content) at the selected index.
69 Tab* GetSelectedTab();
70
71 // Returns the content View of the currently selected Tab.
72 View* GetSelectedTabContentView();
73
74 // Moves the selection by |delta| tabs, where negative delta means leftwards
75 // and positive delta means rightwards. Returns whether the selection could be
76 // moved by that amount; the only way this can fail is if there is only one
77 // tab.
78 bool MoveSelectionBy(int delta);
79
66 // Overridden from View: 80 // Overridden from View:
67 void Layout() override; 81 void Layout() override;
68 void ViewHierarchyChanged( 82 void ViewHierarchyChanged(
69 const ViewHierarchyChangedDetails& details) override; 83 const ViewHierarchyChangedDetails& details) override;
70 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; 84 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
71 void OnFocus() override;
72 void GetAccessibleState(ui::AXViewState* state) override; 85 void GetAccessibleState(ui::AXViewState* state) override;
73 86
74 // A listener notified when tab selection changes. Weak, not owned. 87 // A listener notified when tab selection changes. Weak, not owned.
75 TabbedPaneListener* listener_; 88 TabbedPaneListener* listener_;
76 89
77 // The tab strip and contents container. The child indices of these members 90 // The tab strip and contents container. The child indices of these members
78 // correspond to match each Tab with its respective content View. 91 // correspond to match each Tab with its respective content View.
79 TabStrip* tab_strip_; 92 TabStrip* tab_strip_;
80 View* contents_; 93 View* contents_;
81 94
82 // The selected tab index or -1 if invalid. 95 // The selected tab index or -1 if invalid.
83 int selected_tab_index_; 96 int selected_tab_index_;
84 97
85 DISALLOW_COPY_AND_ASSIGN(TabbedPane); 98 DISALLOW_COPY_AND_ASSIGN(TabbedPane);
86 }; 99 };
87 100
101 // The tab view shown in the tab strip.
102 class Tab : public View {
103 public:
104 // Internal class name.
105 static const char kViewClassName[];
106
107 Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents);
108 ~Tab() override;
109
110 View* contents() const { return contents_; }
111
112 bool selected() const { return contents_->visible(); }
113 void SetSelected(bool selected);
114
115 // Overridden from View:
116 bool OnMousePressed(const ui::MouseEvent& event) override;
117 void OnMouseEntered(const ui::MouseEvent& event) override;
118 void OnMouseExited(const ui::MouseEvent& event) override;
119 void OnGestureEvent(ui::GestureEvent* event) override;
120 gfx::Size GetPreferredSize() const override;
121 void Layout() override;
122 const char* GetClassName() const override;
123 void OnFocus() override;
124 void OnBlur() override;
125 bool OnKeyPressed(const ui::KeyEvent& event) override;
126
127 protected:
128 Label* title() { return title_; }
129
130 // Called whenever |tab_state_| changes.
131 virtual void OnStateChanged();
132
133 // Returns whether the containing TabStrip has focus.
134 bool ContainerHasFocus();
135
136 private:
137 enum TabState {
138 TAB_INACTIVE,
139 TAB_ACTIVE,
140 TAB_HOVERED,
141 };
142
143 void SetState(TabState tab_state);
144
145 TabbedPane* tabbed_pane_;
146 Label* title_;
147 gfx::Size preferred_title_size_;
148 TabState tab_state_;
149 // The content view associated with this tab.
150 View* contents_;
151
152 DISALLOW_COPY_AND_ASSIGN(Tab);
153 };
154
88 } // namespace views 155 } // namespace views
89 156
90 #endif // UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_ 157 #endif // UI_VIEWS_CONTROLS_TABBED_PANE_TABBED_PANE_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/tabbed_pane/tabbed_pane.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698