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

Side by Side Diff: ui/message_center/views/notifier_settings_view.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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/message_center/views/notifier_settings_view.h" 5 #include "ui/message_center/views/notifier_settings_view.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 // The view to guarantee the 48px height and place the contents at the 131 // The view to guarantee the 48px height and place the contents at the
132 // middle. It also guarantee the left margin. 132 // middle. It also guarantee the left margin.
133 class EntryView : public views::View { 133 class EntryView : public views::View {
134 public: 134 public:
135 explicit EntryView(views::View* contents); 135 explicit EntryView(views::View* contents);
136 virtual ~EntryView(); 136 virtual ~EntryView();
137 137
138 // views::View: 138 // views::View:
139 virtual void Layout() OVERRIDE; 139 virtual void Layout() OVERRIDE;
140 virtual gfx::Size GetPreferredSize() OVERRIDE; 140 virtual gfx::Size GetPreferredSize() const OVERRIDE;
141 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE; 141 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
142 virtual void OnFocus() OVERRIDE; 142 virtual void OnFocus() OVERRIDE;
143 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; 143 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
144 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; 144 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE;
145 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 145 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
146 virtual void OnBlur() OVERRIDE; 146 virtual void OnBlur() OVERRIDE;
147 147
148 private: 148 private:
149 scoped_ptr<views::Painter> focus_painter_; 149 scoped_ptr<views::Painter> focus_painter_;
150 150
151 DISALLOW_COPY_AND_ASSIGN(EntryView); 151 DISALLOW_COPY_AND_ASSIGN(EntryView);
152 }; 152 };
153 153
154 EntryView::EntryView(views::View* contents) 154 EntryView::EntryView(views::View* contents)
155 : focus_painter_(CreateFocusPainter()) { 155 : focus_painter_(CreateFocusPainter()) {
156 AddChildView(contents); 156 AddChildView(contents);
157 } 157 }
158 158
159 EntryView::~EntryView() {} 159 EntryView::~EntryView() {}
160 160
161 void EntryView::Layout() { 161 void EntryView::Layout() {
162 DCHECK_EQ(1, child_count()); 162 DCHECK_EQ(1, child_count());
163 views::View* content = child_at(0); 163 views::View* content = child_at(0);
164 int content_width = width(); 164 int content_width = width();
165 int content_height = content->GetHeightForWidth(content_width); 165 int content_height = content->GetHeightForWidth(content_width);
166 int y = std::max((height() - content_height) / 2, 0); 166 int y = std::max((height() - content_height) / 2, 0);
167 content->SetBounds(0, y, content_width, content_height); 167 content->SetBounds(0, y, content_width, content_height);
168 } 168 }
169 169
170 gfx::Size EntryView::GetPreferredSize() { 170 gfx::Size EntryView::GetPreferredSize() const {
171 DCHECK_EQ(1, child_count()); 171 DCHECK_EQ(1, child_count());
172 gfx::Size size = child_at(0)->GetPreferredSize(); 172 gfx::Size size = child_at(0)->GetPreferredSize();
173 size.SetToMax(gfx::Size(settings::kWidth, settings::kEntryHeight)); 173 size.SetToMax(gfx::Size(settings::kWidth, settings::kEntryHeight));
174 return size; 174 return size;
175 } 175 }
176 176
177 void EntryView::GetAccessibleState(ui::AXViewState* state) { 177 void EntryView::GetAccessibleState(ui::AXViewState* state) {
178 DCHECK_EQ(1, child_count()); 178 DCHECK_EQ(1, child_count());
179 child_at(0)->GetAccessibleState(state); 179 child_at(0)->GetAccessibleState(state);
180 } 180 }
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 int content_width = width(); 645 int content_width = width();
646 int content_height = contents_view->GetHeightForWidth(content_width); 646 int content_height = contents_view->GetHeightForWidth(content_width);
647 if (title_height + content_height > height()) { 647 if (title_height + content_height > height()) {
648 content_width -= scroller_->GetScrollBarWidth(); 648 content_width -= scroller_->GetScrollBarWidth();
649 content_height = contents_view->GetHeightForWidth(content_width); 649 content_height = contents_view->GetHeightForWidth(content_width);
650 } 650 }
651 contents_view->SetBounds(0, 0, content_width, content_height); 651 contents_view->SetBounds(0, 0, content_width, content_height);
652 scroller_->SetBounds(0, title_height, width(), height() - title_height); 652 scroller_->SetBounds(0, title_height, width(), height() - title_height);
653 } 653 }
654 654
655 gfx::Size NotifierSettingsView::GetMinimumSize() { 655 gfx::Size NotifierSettingsView::GetMinimumSize() const {
656 gfx::Size size(settings::kWidth, settings::kMinimumHeight); 656 gfx::Size size(settings::kWidth, settings::kMinimumHeight);
657 int total_height = title_label_->GetPreferredSize().height() + 657 int total_height = title_label_->GetPreferredSize().height() +
658 scroller_->contents()->GetPreferredSize().height(); 658 scroller_->contents()->GetPreferredSize().height();
659 if (total_height > settings::kMinimumHeight) 659 if (total_height > settings::kMinimumHeight)
660 size.Enlarge(scroller_->GetScrollBarWidth(), 0); 660 size.Enlarge(scroller_->GetScrollBarWidth(), 0);
661 return size; 661 return size;
662 } 662 }
663 663
664 gfx::Size NotifierSettingsView::GetPreferredSize() { 664 gfx::Size NotifierSettingsView::GetPreferredSize() const {
665 gfx::Size preferred_size; 665 gfx::Size preferred_size;
666 gfx::Size title_size = title_label_->GetPreferredSize(); 666 gfx::Size title_size = title_label_->GetPreferredSize();
667 gfx::Size content_size = scroller_->contents()->GetPreferredSize(); 667 gfx::Size content_size = scroller_->contents()->GetPreferredSize();
668 return gfx::Size(std::max(title_size.width(), content_size.width()), 668 return gfx::Size(std::max(title_size.width(), content_size.width()),
669 title_size.height() + content_size.height()); 669 title_size.height() + content_size.height());
670 } 670 }
671 671
672 bool NotifierSettingsView::OnKeyPressed(const ui::KeyEvent& event) { 672 bool NotifierSettingsView::OnKeyPressed(const ui::KeyEvent& event) {
673 if (event.key_code() == ui::VKEY_ESCAPE) { 673 if (event.key_code() == ui::VKEY_ESCAPE) {
674 GetWidget()->Close(); 674 GetWidget()->Close();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 menu_anchor, 715 menu_anchor,
716 views::MENU_ANCHOR_BUBBLE_ABOVE, 716 views::MENU_ANCHOR_BUBBLE_ABOVE,
717 ui::MENU_SOURCE_MOUSE, 717 ui::MENU_SOURCE_MOUSE,
718 views::MenuRunner::CONTEXT_MENU)) 718 views::MenuRunner::CONTEXT_MENU))
719 return; 719 return;
720 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent()); 720 MessageCenterView* center_view = static_cast<MessageCenterView*>(parent());
721 center_view->OnSettingsChanged(); 721 center_view->OnSettingsChanged();
722 } 722 }
723 723
724 } // namespace message_center 724 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/notifier_settings_view.h ('k') | ui/message_center/views/padded_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698