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

Side by Side Diff: chrome/browser/ui/views/profiles/avatar_menu_bubble_view.cc

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" 5 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // ProfileItemView ------------------------------------------------------------ 213 // ProfileItemView ------------------------------------------------------------
214 214
215 // Control that shows information about a single profile. 215 // Control that shows information about a single profile.
216 class ProfileItemView : public views::CustomButton, 216 class ProfileItemView : public views::CustomButton,
217 public HighlightDelegate { 217 public HighlightDelegate {
218 public: 218 public:
219 ProfileItemView(const AvatarMenu::Item& item, 219 ProfileItemView(const AvatarMenu::Item& item,
220 AvatarMenuBubbleView* parent, 220 AvatarMenuBubbleView* parent,
221 AvatarMenu* menu); 221 AvatarMenu* menu);
222 222
223 virtual gfx::Size GetPreferredSize() OVERRIDE; 223 virtual gfx::Size GetPreferredSize() const OVERRIDE;
224 virtual void Layout() OVERRIDE; 224 virtual void Layout() OVERRIDE;
225 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 225 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
226 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 226 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
227 virtual void OnFocus() OVERRIDE; 227 virtual void OnFocus() OVERRIDE;
228 virtual void OnBlur() OVERRIDE; 228 virtual void OnBlur() OVERRIDE;
229 229
230 virtual void OnHighlightStateChanged() OVERRIDE; 230 virtual void OnHighlightStateChanged() OVERRIDE;
231 virtual void OnFocusStateChanged(bool has_focus) OVERRIDE; 231 virtual void OnFocusStateChanged(bool has_focus) OVERRIDE;
232 232
233 const AvatarMenu::Item& item() const { return item_; } 233 const AvatarMenu::Item& item() const { return item_; }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Add an edit profile link. 290 // Add an edit profile link.
291 edit_link_ = new EditProfileLink( 291 edit_link_ = new EditProfileLink(
292 l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this); 292 l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this);
293 edit_link_->set_listener(parent); 293 edit_link_->set_listener(parent);
294 edit_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 294 edit_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
295 AddChildView(edit_link_); 295 AddChildView(edit_link_);
296 296
297 OnHighlightStateChanged(); 297 OnHighlightStateChanged();
298 } 298 }
299 299
300 gfx::Size ProfileItemView::GetPreferredSize() { 300 gfx::Size ProfileItemView::GetPreferredSize() const {
301 int text_width = std::max(name_label_->GetPreferredSize().width(), 301 int text_width = std::max(name_label_->GetPreferredSize().width(),
302 sync_state_label_->GetPreferredSize().width()); 302 sync_state_label_->GetPreferredSize().width());
303 text_width = std::max(edit_link_->GetPreferredSize().width(), text_width); 303 text_width = std::max(edit_link_->GetPreferredSize().width(), text_width);
304 text_width = std::min(kMaxItemTextWidth, text_width); 304 text_width = std::min(kMaxItemTextWidth, text_width);
305 return gfx::Size(profiles::kAvatarIconWidth + kIconMarginX + text_width, 305 return gfx::Size(profiles::kAvatarIconWidth + kIconMarginX + text_width,
306 kItemHeight); 306 kItemHeight);
307 } 307 }
308 308
309 void ProfileItemView::Layout() { 309 void ProfileItemView::Layout() {
310 // Profile icon. 310 // Profile icon.
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 avatar_menu_.reset(new AvatarMenu( 528 avatar_menu_.reset(new AvatarMenu(
529 &g_browser_process->profile_manager()->GetProfileInfoCache(), 529 &g_browser_process->profile_manager()->GetProfileInfoCache(),
530 this, 530 this,
531 browser_)); 531 browser_));
532 avatar_menu_->RebuildMenu(); 532 avatar_menu_->RebuildMenu();
533 } 533 }
534 534
535 AvatarMenuBubbleView::~AvatarMenuBubbleView() { 535 AvatarMenuBubbleView::~AvatarMenuBubbleView() {
536 } 536 }
537 537
538 gfx::Size AvatarMenuBubbleView::GetPreferredSize() { 538 gfx::Size AvatarMenuBubbleView::GetPreferredSize() const {
539 const int kBubbleViewMinWidth = 175; 539 const int kBubbleViewMinWidth = 175;
540 gfx::Size preferred_size(kBubbleViewMinWidth, 0); 540 gfx::Size preferred_size(kBubbleViewMinWidth, 0);
541 for (size_t i = 0; i < item_views_.size(); ++i) { 541 for (size_t i = 0; i < item_views_.size(); ++i) {
542 gfx::Size size = item_views_[i]->GetPreferredSize(); 542 gfx::Size size = item_views_[i]->GetPreferredSize();
543 preferred_size.Enlarge(0, size.height() + kItemMarginY); 543 preferred_size.Enlarge(0, size.height() + kItemMarginY);
544 preferred_size.SetToMax(size); 544 preferred_size.SetToMax(size);
545 } 545 }
546 546
547 if (buttons_view_) { 547 if (buttons_view_) {
548 preferred_size.Enlarge( 548 preferred_size.Enlarge(
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 Layout(); 801 Layout();
802 if (GetBubbleFrameView()) 802 if (GetBubbleFrameView())
803 SizeToContents(); 803 SizeToContents();
804 } 804 }
805 805
806 void AvatarMenuBubbleView::SetBackgroundColors() { 806 void AvatarMenuBubbleView::SetBackgroundColors() {
807 for (size_t i = 0; i < item_views_.size(); ++i) { 807 for (size_t i = 0; i < item_views_.size(); ++i) {
808 item_views_[i]->OnHighlightStateChanged(); 808 item_views_[i]->OnHighlightStateChanged();
809 } 809 }
810 } 810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698