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/controls/tabbed_pane/tabbed_pane.h" | 5 #include "ui/views/controls/tabbed_pane/tabbed_pane.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/base/accessibility/accessible_view_state.h" | 8 #include "ui/base/accessibility/accessible_view_state.h" |
9 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 Tab(TabbedPane* tabbed_pane, const string16& title, View* contents); | 36 Tab(TabbedPane* tabbed_pane, const string16& title, View* contents); |
37 virtual ~Tab(); | 37 virtual ~Tab(); |
38 | 38 |
39 View* contents() const { return contents_; } | 39 View* contents() const { return contents_; } |
40 | 40 |
41 bool selected() const { return contents_->visible(); } | 41 bool selected() const { return contents_->visible(); } |
42 void SetSelected(bool selected); | 42 void SetSelected(bool selected); |
43 | 43 |
44 // Overridden from View: | 44 // Overridden from View: |
45 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 45 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
46 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | |
47 virtual void OnMouseCaptureLost() OVERRIDE; | |
48 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 46 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
49 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 47 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
50 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 48 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
51 virtual gfx::Size GetPreferredSize() OVERRIDE; | 49 virtual gfx::Size GetPreferredSize() OVERRIDE; |
52 virtual void Layout() OVERRIDE; | 50 virtual void Layout() OVERRIDE; |
53 | 51 |
54 private: | 52 private: |
55 enum TabState { | 53 enum TabState { |
56 TAB_INACTIVE, | 54 TAB_INACTIVE, |
57 TAB_ACTIVE, | 55 TAB_ACTIVE, |
58 TAB_PRESSED, | |
59 TAB_HOVERED, | 56 TAB_HOVERED, |
60 }; | 57 }; |
61 | 58 |
62 void SetState(TabState tab_state); | 59 void SetState(TabState tab_state); |
63 | 60 |
64 TabbedPane* tabbed_pane_; | 61 TabbedPane* tabbed_pane_; |
65 Label* title_; | 62 Label* title_; |
66 gfx::Size preferred_title_size_; | 63 gfx::Size preferred_title_size_; |
67 TabState tab_state_; | 64 TabState tab_state_; |
68 // The content view associated with this tab. | 65 // The content view associated with this tab. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } | 98 } |
102 | 99 |
103 Tab::~Tab() {} | 100 Tab::~Tab() {} |
104 | 101 |
105 void Tab::SetSelected(bool selected) { | 102 void Tab::SetSelected(bool selected) { |
106 contents_->SetVisible(selected); | 103 contents_->SetVisible(selected); |
107 SetState(selected ? TAB_ACTIVE : TAB_INACTIVE); | 104 SetState(selected ? TAB_ACTIVE : TAB_INACTIVE); |
108 } | 105 } |
109 | 106 |
110 bool Tab::OnMousePressed(const ui::MouseEvent& event) { | 107 bool Tab::OnMousePressed(const ui::MouseEvent& event) { |
111 SetState(TAB_PRESSED); | 108 if (event.IsOnlyLeftMouseButton() && |
| 109 GetLocalBounds().Contains(event.location())) |
| 110 tabbed_pane_->SelectTab(this); |
112 return true; | 111 return true; |
113 } | 112 } |
114 | 113 |
115 void Tab::OnMouseReleased(const ui::MouseEvent& event) { | |
116 SetState(selected() ? TAB_ACTIVE : TAB_HOVERED); | |
117 if (GetLocalBounds().Contains(event.location())) | |
118 tabbed_pane_->SelectTab(this); | |
119 } | |
120 | |
121 void Tab::OnMouseCaptureLost() { | |
122 SetState(TAB_INACTIVE); | |
123 } | |
124 | |
125 void Tab::OnMouseEntered(const ui::MouseEvent& event) { | 114 void Tab::OnMouseEntered(const ui::MouseEvent& event) { |
126 SetState(selected() ? TAB_ACTIVE : TAB_HOVERED); | 115 SetState(selected() ? TAB_ACTIVE : TAB_HOVERED); |
127 } | 116 } |
128 | 117 |
129 void Tab::OnMouseExited(const ui::MouseEvent& event) { | 118 void Tab::OnMouseExited(const ui::MouseEvent& event) { |
130 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); | 119 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); |
131 } | 120 } |
132 | 121 |
133 void Tab::OnGestureEvent(ui::GestureEvent* event) { | 122 void Tab::OnGestureEvent(ui::GestureEvent* event) { |
134 switch (event->type()) { | 123 switch (event->type()) { |
135 case ui::ET_GESTURE_TAP_DOWN: | 124 case ui::ET_GESTURE_TAP_DOWN: |
136 SetState(TAB_PRESSED); | 125 // Fallthrough. |
137 break; | |
138 case ui::ET_GESTURE_TAP: | 126 case ui::ET_GESTURE_TAP: |
139 // SelectTab also sets the right tab color. | 127 // SelectTab also sets the right tab color. |
140 tabbed_pane_->SelectTab(this); | 128 tabbed_pane_->SelectTab(this); |
141 break; | 129 break; |
142 case ui::ET_GESTURE_TAP_CANCEL: | 130 case ui::ET_GESTURE_TAP_CANCEL: |
143 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); | 131 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); |
144 break; | 132 break; |
145 default: | 133 default: |
146 break; | 134 break; |
147 } | 135 } |
(...skipping 23 matching lines...) Expand all Loading... |
171 | 159 |
172 switch (tab_state) { | 160 switch (tab_state) { |
173 case TAB_INACTIVE: | 161 case TAB_INACTIVE: |
174 title_->SetEnabledColor(kTabTitleColor_Inactive); | 162 title_->SetEnabledColor(kTabTitleColor_Inactive); |
175 title_->SetFont(gfx::Font()); | 163 title_->SetFont(gfx::Font()); |
176 break; | 164 break; |
177 case TAB_ACTIVE: | 165 case TAB_ACTIVE: |
178 title_->SetEnabledColor(kTabTitleColor_Active); | 166 title_->SetEnabledColor(kTabTitleColor_Active); |
179 title_->SetFont(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); | 167 title_->SetFont(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); |
180 break; | 168 break; |
181 case TAB_PRESSED: | |
182 // No visual distinction for pressed state. | |
183 break; | |
184 case TAB_HOVERED: | 169 case TAB_HOVERED: |
185 title_->SetEnabledColor(kTabTitleColor_Hovered); | 170 title_->SetEnabledColor(kTabTitleColor_Hovered); |
186 title_->SetFont(gfx::Font()); | 171 title_->SetFont(gfx::Font()); |
187 break; | 172 break; |
188 } | 173 } |
189 SchedulePaint(); | 174 SchedulePaint(); |
190 } | 175 } |
191 | 176 |
192 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {} | 177 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {} |
193 | 178 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 selected_tab->NotifyAccessibilityEvent( | 369 selected_tab->NotifyAccessibilityEvent( |
385 ui::AccessibilityTypes::EVENT_FOCUS, true); | 370 ui::AccessibilityTypes::EVENT_FOCUS, true); |
386 } | 371 } |
387 } | 372 } |
388 | 373 |
389 void TabbedPane::GetAccessibleState(ui::AccessibleViewState* state) { | 374 void TabbedPane::GetAccessibleState(ui::AccessibleViewState* state) { |
390 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 375 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
391 } | 376 } |
392 | 377 |
393 } // namespace views | 378 } // namespace views |
OLD | NEW |