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

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

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More compile fix for ToT Created 6 years, 7 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 | Annotate | Revision Log
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 #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/accessibility/ax_view_state.h" 8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
(...skipping 29 matching lines...) Expand all
40 View* contents() const { return contents_; } 40 View* contents() const { return contents_; }
41 41
42 bool selected() const { return contents_->visible(); } 42 bool selected() const { return contents_->visible(); }
43 void SetSelected(bool selected); 43 void SetSelected(bool selected);
44 44
45 // Overridden from View: 45 // Overridden from View:
46 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 46 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
47 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 47 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
48 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 48 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
49 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 49 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
50 virtual gfx::Size GetPreferredSize() OVERRIDE; 50 virtual gfx::Size GetPreferredSize() const OVERRIDE;
51 virtual void Layout() OVERRIDE; 51 virtual void Layout() OVERRIDE;
52 52
53 private: 53 private:
54 enum TabState { 54 enum TabState {
55 TAB_INACTIVE, 55 TAB_INACTIVE,
56 TAB_ACTIVE, 56 TAB_ACTIVE,
57 TAB_HOVERED, 57 TAB_HOVERED,
58 }; 58 };
59 59
60 void SetState(TabState tab_state); 60 void SetState(TabState tab_state);
61 61
62 TabbedPane* tabbed_pane_; 62 TabbedPane* tabbed_pane_;
63 Label* title_; 63 Label* title_;
64 gfx::Size preferred_title_size_; 64 gfx::Size preferred_title_size_;
65 TabState tab_state_; 65 TabState tab_state_;
66 // The content view associated with this tab. 66 // The content view associated with this tab.
67 View* contents_; 67 View* contents_;
68 68
69 DISALLOW_COPY_AND_ASSIGN(Tab); 69 DISALLOW_COPY_AND_ASSIGN(Tab);
70 }; 70 };
71 71
72 // The tab strip shown above the tab contents. 72 // The tab strip shown above the tab contents.
73 class TabStrip : public View { 73 class TabStrip : public View {
74 public: 74 public:
75 explicit TabStrip(TabbedPane* tabbed_pane); 75 explicit TabStrip(TabbedPane* tabbed_pane);
76 virtual ~TabStrip(); 76 virtual ~TabStrip();
77 77
78 // Overridden from View: 78 // Overridden from View:
79 virtual gfx::Size GetPreferredSize() OVERRIDE; 79 virtual gfx::Size GetPreferredSize() const OVERRIDE;
80 virtual void Layout() OVERRIDE; 80 virtual void Layout() OVERRIDE;
81 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 81 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
82 82
83 private: 83 private:
84 TabbedPane* tabbed_pane_; 84 TabbedPane* tabbed_pane_;
85 85
86 DISALLOW_COPY_AND_ASSIGN(TabStrip); 86 DISALLOW_COPY_AND_ASSIGN(TabStrip);
87 }; 87 };
88 88
89 Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents) 89 Tab::Tab(TabbedPane* tabbed_pane, const base::string16& title, View* contents)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 break; 132 break;
133 case ui::ET_GESTURE_TAP_CANCEL: 133 case ui::ET_GESTURE_TAP_CANCEL:
134 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE); 134 SetState(selected() ? TAB_ACTIVE : TAB_INACTIVE);
135 break; 135 break;
136 default: 136 default:
137 break; 137 break;
138 } 138 }
139 event->SetHandled(); 139 event->SetHandled();
140 } 140 }
141 141
142 gfx::Size Tab::GetPreferredSize() { 142 gfx::Size Tab::GetPreferredSize() const {
143 gfx::Size size(preferred_title_size_); 143 gfx::Size size(preferred_title_size_);
144 size.Enlarge(21, 9); 144 size.Enlarge(21, 9);
145 const int kTabMinWidth = 54; 145 const int kTabMinWidth = 54;
146 if (size.width() < kTabMinWidth) 146 if (size.width() < kTabMinWidth)
147 size.set_width(kTabMinWidth); 147 size.set_width(kTabMinWidth);
148 return size; 148 return size;
149 } 149 }
150 150
151 void Tab::Layout() { 151 void Tab::Layout() {
152 gfx::Rect bounds = GetLocalBounds(); 152 gfx::Rect bounds = GetLocalBounds();
(...skipping 22 matching lines...) Expand all
175 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::BaseFont)); 175 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::BaseFont));
176 break; 176 break;
177 } 177 }
178 SchedulePaint(); 178 SchedulePaint();
179 } 179 }
180 180
181 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {} 181 TabStrip::TabStrip(TabbedPane* tabbed_pane) : tabbed_pane_(tabbed_pane) {}
182 182
183 TabStrip::~TabStrip() {} 183 TabStrip::~TabStrip() {}
184 184
185 gfx::Size TabStrip::GetPreferredSize() { 185 gfx::Size TabStrip::GetPreferredSize() const {
186 gfx::Size size; 186 gfx::Size size;
187 for (int i = 0; i < child_count(); ++i) { 187 for (int i = 0; i < child_count(); ++i) {
188 const gfx::Size child_size = child_at(i)->GetPreferredSize(); 188 const gfx::Size child_size = child_at(i)->GetPreferredSize();
189 size.SetSize(size.width() + child_size.width(), 189 size.SetSize(size.width() + child_size.width(),
190 std::max(size.height(), child_size.height())); 190 std::max(size.height(), child_size.height()));
191 } 191 }
192 return size; 192 return size;
193 } 193 }
194 194
195 void TabStrip::Layout() { 195 void TabStrip::Layout() {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 if (listener()) 301 if (listener())
302 listener()->TabSelectedAt(index); 302 listener()->TabSelectedAt(index);
303 } 303 }
304 304
305 void TabbedPane::SelectTab(Tab* tab) { 305 void TabbedPane::SelectTab(Tab* tab) {
306 const int index = tab_strip_->GetIndexOf(tab); 306 const int index = tab_strip_->GetIndexOf(tab);
307 if (index >= 0) 307 if (index >= 0)
308 SelectTabAt(index); 308 SelectTabAt(index);
309 } 309 }
310 310
311 gfx::Size TabbedPane::GetPreferredSize() { 311 gfx::Size TabbedPane::GetPreferredSize() const {
312 gfx::Size size; 312 gfx::Size size;
313 for (int i = 0; i < contents_->child_count(); ++i) 313 for (int i = 0; i < contents_->child_count(); ++i)
314 size.SetToMax(contents_->child_at(i)->GetPreferredSize()); 314 size.SetToMax(contents_->child_at(i)->GetPreferredSize());
315 size.Enlarge(0, tab_strip_->GetPreferredSize().height()); 315 size.Enlarge(0, tab_strip_->GetPreferredSize().height());
316 return size; 316 return size;
317 } 317 }
318 318
319 Tab* TabbedPane::GetTabAt(int index) { 319 Tab* TabbedPane::GetTabAt(int index) {
320 return static_cast<Tab*>(tab_strip_->child_at(index)); 320 return static_cast<Tab*>(tab_strip_->child_at(index));
321 } 321 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 selected_tab->NotifyAccessibilityEvent( 366 selected_tab->NotifyAccessibilityEvent(
367 ui::AX_EVENT_FOCUS, true); 367 ui::AX_EVENT_FOCUS, true);
368 } 368 }
369 } 369 }
370 370
371 void TabbedPane::GetAccessibleState(ui::AXViewState* state) { 371 void TabbedPane::GetAccessibleState(ui::AXViewState* state) {
372 state->role = ui::AX_ROLE_TAB_LIST; 372 state->role = ui::AX_ROLE_TAB_LIST;
373 } 373 }
374 374
375 } // namespace views 375 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/tabbed_pane/tabbed_pane.h ('k') | ui/views/controls/tabbed_pane/tabbed_pane_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698