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 #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 (GetLocalBounds().Contains(event.location())) |
|
sky
2013/11/12 17:03:01
Only on left mouse button?
msw
2013/11/12 18:48:51
Done.
| |
| 109 tabbed_pane_->SelectTab(this); | |
| 112 return true; | 110 return true; |
| 113 } | 111 } |
| 114 | 112 |
| 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) { | 113 void Tab::OnMouseEntered(const ui::MouseEvent& event) { |
| 126 SetState(selected() ? TAB_ACTIVE : TAB_HOVERED); | 114 SetState(selected() ? TAB_ACTIVE : TAB_HOVERED); |
| 127 } | 115 } |
| 128 | 116 |
| 129 void Tab::OnMouseExited(const ui::MouseEvent& event) { | 117 void Tab::OnMouseExited(const ui::MouseEvent& event) { |
| 130 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); | 118 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); |
| 131 } | 119 } |
| 132 | 120 |
| 133 void Tab::OnGestureEvent(ui::GestureEvent* event) { | 121 void Tab::OnGestureEvent(ui::GestureEvent* event) { |
| 134 switch (event->type()) { | 122 switch (event->type()) { |
| 135 case ui::ET_GESTURE_TAP_DOWN: | 123 case ui::ET_GESTURE_TAP_DOWN: |
| 136 SetState(TAB_PRESSED); | 124 // Fallthrough. |
| 137 break; | |
| 138 case ui::ET_GESTURE_TAP: | 125 case ui::ET_GESTURE_TAP: |
| 139 // SelectTab also sets the right tab color. | 126 // SelectTab also sets the right tab color. |
| 140 tabbed_pane_->SelectTab(this); | 127 tabbed_pane_->SelectTab(this); |
| 141 break; | 128 break; |
| 142 case ui::ET_GESTURE_TAP_CANCEL: | 129 case ui::ET_GESTURE_TAP_CANCEL: |
| 143 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); | 130 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); |
| 144 break; | 131 break; |
| 145 default: | 132 default: |
| 146 break; | 133 break; |
| 147 } | 134 } |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 171 | 158 |
| 172 switch (tab_state) { | 159 switch (tab_state) { |
| 173 case TAB_INACTIVE: | 160 case TAB_INACTIVE: |
| 174 title_->SetEnabledColor(kTabTitleColor_Inactive); | 161 title_->SetEnabledColor(kTabTitleColor_Inactive); |
| 175 title_->SetFont(gfx::Font()); | 162 title_->SetFont(gfx::Font()); |
| 176 break; | 163 break; |
| 177 case TAB_ACTIVE: | 164 case TAB_ACTIVE: |
| 178 title_->SetEnabledColor(kTabTitleColor_Active); | 165 title_->SetEnabledColor(kTabTitleColor_Active); |
| 179 title_->SetFont(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); | 166 title_->SetFont(gfx::Font().DeriveFont(0, gfx::Font::BOLD)); |
| 180 break; | 167 break; |
| 181 case TAB_PRESSED: | |
| 182 // No visual distinction for pressed state. | |
| 183 break; | |
| 184 case TAB_HOVERED: | 168 case TAB_HOVERED: |
| 185 title_->SetEnabledColor(kTabTitleColor_Hovered); | 169 title_->SetEnabledColor(kTabTitleColor_Hovered); |
| 186 title_->SetFont(gfx::Font()); | 170 title_->SetFont(gfx::Font()); |
| 187 break; | 171 break; |
| 188 } | 172 } |
| 189 SchedulePaint(); | 173 SchedulePaint(); |
| 190 } | 174 } |
| 191 | 175 |
| 192 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {} | 176 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {} |
| 193 | 177 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 selected_tab->NotifyAccessibilityEvent( | 368 selected_tab->NotifyAccessibilityEvent( |
| 385 ui::AccessibilityTypes::EVENT_FOCUS, true); | 369 ui::AccessibilityTypes::EVENT_FOCUS, true); |
| 386 } | 370 } |
| 387 } | 371 } |
| 388 | 372 |
| 389 void TabbedPane::GetAccessibleState(ui::AccessibleViewState* state) { | 373 void TabbedPane::GetAccessibleState(ui::AccessibleViewState* state) { |
| 390 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 374 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
| 391 } | 375 } |
| 392 | 376 |
| 393 } // namespace views | 377 } // namespace views |
| OLD | NEW |