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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc

Issue 2065653002: Vertically align text on empty bookmarks bar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed descend/ascent calculations and alignment code from GetPreferredSize() Created 4 years, 6 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
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/defaults.h" 10 #include "chrome/browser/defaults.h"
(...skipping 22 matching lines...) Expand all
33 return 6; 33 return 6;
34 } 34 }
35 35
36 } // namespace 36 } // namespace
37 37
38 BookmarkBarInstructionsView::BookmarkBarInstructionsView( 38 BookmarkBarInstructionsView::BookmarkBarInstructionsView(
39 BookmarkBarInstructionsDelegate* delegate) 39 BookmarkBarInstructionsDelegate* delegate)
40 : delegate_(delegate), 40 : delegate_(delegate),
41 instructions_(NULL), 41 instructions_(NULL),
42 import_link_(NULL), 42 import_link_(NULL),
43 baseline_(-1),
44 updated_colors_(false) { 43 updated_colors_(false) {
45 instructions_ = new views::Label( 44 instructions_ = new views::Label(
46 l10n_util::GetStringUTF16(IDS_BOOKMARKS_NO_ITEMS)); 45 l10n_util::GetStringUTF16(IDS_BOOKMARKS_NO_ITEMS));
47 instructions_->SetAutoColorReadabilityEnabled(false); 46 instructions_->SetAutoColorReadabilityEnabled(false);
48 instructions_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 47 instructions_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
49 AddChildView(instructions_); 48 AddChildView(instructions_);
50 49
51 if (browser_defaults::kShowImportOnBookmarkBar) { 50 if (browser_defaults::kShowImportOnBookmarkBar) {
52 import_link_ = new views::Link( 51 import_link_ = new views::Link(
53 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_IMPORT_LINK)); 52 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_IMPORT_LINK));
54 // We don't want the link to alter tab navigation. 53 // We don't want the link to alter tab navigation.
55 import_link_->SetFocusBehavior(FocusBehavior::NEVER); 54 import_link_->SetFocusBehavior(FocusBehavior::NEVER);
56 import_link_->set_listener(this); 55 import_link_->set_listener(this);
57 import_link_->set_context_menu_controller(this); 56 import_link_->set_context_menu_controller(this);
58 import_link_->SetAutoColorReadabilityEnabled(false); 57 import_link_->SetAutoColorReadabilityEnabled(false);
59 import_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 58 import_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
60 AddChildView(import_link_); 59 AddChildView(import_link_);
61 } 60 }
62 } 61 }
63 62
64 gfx::Size BookmarkBarInstructionsView::GetPreferredSize() const { 63 gfx::Size BookmarkBarInstructionsView::GetPreferredSize() const {
65 int ascent = 0, descent = 0, height = 0, width = 0; 64 int height = 0, width = 0;
66 for (int i = 0; i < child_count(); ++i) { 65 for (int i = 0; i < child_count(); ++i) {
67 const views::View* view = child_at(i); 66 const views::View* view = child_at(i);
68 gfx::Size pref = view->GetPreferredSize(); 67 gfx::Size pref = view->GetPreferredSize();
69 int baseline = view->GetBaseline(); 68 height = std::max(pref.height(), height);
70 if (baseline != -1) {
71 ascent = std::max(ascent, baseline);
72 descent = std::max(descent, pref.height() - baseline);
73 } else {
74 height = std::max(pref.height(), height);
75 }
76 width += pref.width(); 69 width += pref.width();
77 } 70 }
78 width += (child_count() - 1) * GetViewPadding(); 71 width += (child_count() - 1) * GetViewPadding();
79 if (ascent != 0)
80 height = std::max(ascent + descent, height);
81 return gfx::Size(width, height); 72 return gfx::Size(width, height);
82 } 73 }
83 74
84 void BookmarkBarInstructionsView::Layout() { 75 void BookmarkBarInstructionsView::Layout() {
85 int remaining_width = width(); 76 int remaining_width = width();
86 int x = 0; 77 int x = 0;
87 for (int i = 0; i < child_count(); ++i) { 78 for (int i = 0; i < child_count(); ++i) {
88 views::View* view = child_at(i); 79 views::View* view = child_at(i);
89 gfx::Size pref = view->GetPreferredSize(); 80 gfx::Size pref = view->GetPreferredSize();
90 int baseline = view->GetBaseline();
91 int y;
92 if (baseline != -1 && baseline_ != -1)
93 y = baseline_ - baseline;
94 else
95 y = (height() - pref.height()) / 2;
96 int view_width = std::min(remaining_width, pref.width()); 81 int view_width = std::min(remaining_width, pref.width());
97 view->SetBounds(x, y, view_width, pref.height()); 82 view->SetBounds(x, 0, view_width, height());
98 x += view_width + GetViewPadding(); 83 x += view_width + GetViewPadding();
99 remaining_width = std::max(0, width() - x); 84 remaining_width = std::max(0, width() - x);
100 } 85 }
101 } 86 }
102 87
103 const char* BookmarkBarInstructionsView::GetClassName() const { 88 const char* BookmarkBarInstructionsView::GetClassName() const {
104 return "BookmarkBarInstructionsView"; 89 return "BookmarkBarInstructionsView";
105 } 90 }
106 91
107 void BookmarkBarInstructionsView::OnThemeChanged() { 92 void BookmarkBarInstructionsView::OnThemeChanged() {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // code (which only adjusts luminance) doesn't work well in this case. 138 // code (which only adjusts luminance) doesn't work well in this case.
154 SkColor bg = theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR); 139 SkColor bg = theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR);
155 SkColor link_color = 140 SkColor link_color =
156 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); 141 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled);
157 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >= 142 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >=
158 color_utils::kMinimumReadableContrastRatio; 143 color_utils::kMinimumReadableContrastRatio;
159 import_link_->SetUnderline(!link_has_contrast); 144 import_link_->SetUnderline(!link_has_contrast);
160 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color); 145 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color);
161 } 146 }
162 } 147 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698