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 15 matching lines...) Expand all Loading... |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 namespace views { | 28 namespace views { |
29 | 29 |
30 // static | 30 // static |
31 const char TabbedPane::kViewClassName[] = "TabbedPane"; | 31 const char TabbedPane::kViewClassName[] = "TabbedPane"; |
32 | 32 |
33 // The tab view shown in the tab strip. | 33 // The tab view shown in the tab strip. |
34 class Tab : public View { | 34 class Tab : public View { |
35 public: | 35 public: |
36 Tab(TabbedPane* tabbed_pane, const string16& title, View* contents); | 36 Tab(TabbedPane* tabbed_pane, const base::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 OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 46 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 virtual gfx::Size GetPreferredSize() OVERRIDE; | 78 virtual gfx::Size GetPreferredSize() OVERRIDE; |
79 virtual void Layout() OVERRIDE; | 79 virtual void Layout() OVERRIDE; |
80 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 80 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
81 | 81 |
82 private: | 82 private: |
83 TabbedPane* tabbed_pane_; | 83 TabbedPane* tabbed_pane_; |
84 | 84 |
85 DISALLOW_COPY_AND_ASSIGN(TabStrip); | 85 DISALLOW_COPY_AND_ASSIGN(TabStrip); |
86 }; | 86 }; |
87 | 87 |
88 Tab::Tab(TabbedPane* tabbed_pane, const string16& title, View* contents) | 88 Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents) |
89 : tabbed_pane_(tabbed_pane), | 89 : tabbed_pane_(tabbed_pane), |
90 title_(new Label(title, gfx::Font().DeriveFont(0, gfx::Font::BOLD))), | 90 title_(new Label(title, gfx::Font().DeriveFont(0, gfx::Font::BOLD))), |
91 tab_state_(TAB_ACTIVE), | 91 tab_state_(TAB_ACTIVE), |
92 contents_(contents) { | 92 contents_(contents) { |
93 // Calculate this now while the font is guaranteed to be bold. | 93 // Calculate this now while the font is guaranteed to be bold. |
94 preferred_title_size_ = title_->GetPreferredSize(); | 94 preferred_title_size_ = title_->GetPreferredSize(); |
95 | 95 |
96 SetState(TAB_INACTIVE); | 96 SetState(TAB_INACTIVE); |
97 AddChildView(title_); | 97 AddChildView(title_); |
98 } | 98 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 int TabbedPane::GetTabCount() { | 248 int TabbedPane::GetTabCount() { |
249 DCHECK_EQ(tab_strip_->child_count(), contents_->child_count()); | 249 DCHECK_EQ(tab_strip_->child_count(), contents_->child_count()); |
250 return contents_->child_count(); | 250 return contents_->child_count(); |
251 } | 251 } |
252 | 252 |
253 View* TabbedPane::GetSelectedTab() { | 253 View* TabbedPane::GetSelectedTab() { |
254 return selected_tab_index() < 0 ? | 254 return selected_tab_index() < 0 ? |
255 NULL : GetTabAt(selected_tab_index())->contents(); | 255 NULL : GetTabAt(selected_tab_index())->contents(); |
256 } | 256 } |
257 | 257 |
258 void TabbedPane::AddTab(const string16& title, View* contents) { | 258 void TabbedPane::AddTab(const base::string16& title, View* contents) { |
259 AddTabAtIndex(tab_strip_->child_count(), title, contents); | 259 AddTabAtIndex(tab_strip_->child_count(), title, contents); |
260 } | 260 } |
261 | 261 |
262 void TabbedPane::AddTabAtIndex(int index, | 262 void TabbedPane::AddTabAtIndex(int index, |
263 const string16& title, | 263 const base::string16& title, |
264 View* contents) { | 264 View* contents) { |
265 DCHECK(index >= 0 && index <= GetTabCount()); | 265 DCHECK(index >= 0 && index <= GetTabCount()); |
266 contents->SetVisible(false); | 266 contents->SetVisible(false); |
267 | 267 |
268 tab_strip_->AddChildViewAt(new Tab(this, title, contents), index); | 268 tab_strip_->AddChildViewAt(new Tab(this, title, contents), index); |
269 contents_->AddChildViewAt(contents, index); | 269 contents_->AddChildViewAt(contents, index); |
270 if (selected_tab_index() < 0) | 270 if (selected_tab_index() < 0) |
271 SelectTabAt(index); | 271 SelectTabAt(index); |
272 | 272 |
273 PreferredSizeChanged(); | 273 PreferredSizeChanged(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 selected_tab->NotifyAccessibilityEvent( | 362 selected_tab->NotifyAccessibilityEvent( |
363 ui::AccessibilityTypes::EVENT_FOCUS, true); | 363 ui::AccessibilityTypes::EVENT_FOCUS, true); |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 void TabbedPane::GetAccessibleState(ui::AccessibleViewState* state) { | 367 void TabbedPane::GetAccessibleState(ui::AccessibleViewState* state) { |
368 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 368 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
369 } | 369 } |
370 | 370 |
371 } // namespace views | 371 } // namespace views |
OLD | NEW |