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

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

Issue 1408273002: Make some updates to BM bar for MD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: format Created 5 years, 2 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
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"
11 #include "chrome/browser/themes/theme_properties.h" 11 #include "chrome/browser/themes/theme_properties.h"
12 #include "chrome/browser/ui/bookmarks/bookmark_bar_instructions_delegate.h" 12 #include "chrome/browser/ui/bookmarks/bookmark_bar_instructions_delegate.h"
13 #include "chrome/grit/generated_resources.h" 13 #include "chrome/grit/generated_resources.h"
14 #include "ui/accessibility/ax_view_state.h" 14 #include "ui/accessibility/ax_view_state.h"
15 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/material_design/material_design_controller.h"
16 #include "ui/base/theme_provider.h" 17 #include "ui/base/theme_provider.h"
18 #include "ui/native_theme/native_theme.h"
17 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
18 #include "ui/views/controls/link.h" 20 #include "ui/views/controls/link.h"
19 21
20 namespace { 22 namespace {
21 23
22 // Horizontal padding, in pixels, between the link and label. 24 // Horizontal padding, in pixels, between the link and label.
23 const int kViewPadding = 6; 25 const int GetViewPadding() {
26 if (ui::MaterialDesignController::IsModeMaterial())
27 return views::Label(base::ASCIIToUTF16(" ")).GetPreferredSize().width();
sky 2015/10/26 23:56:38 Can we cache this? We don't really support changin
Evan Stade 2015/10/27 17:05:42 hmm, you're right. I thought we did support live f
28
29 // Pre-MD is hard-coded to 6px.
30 return 6;
31 }
24 32
25 } // namespace 33 } // namespace
26 34
27 BookmarkBarInstructionsView::BookmarkBarInstructionsView( 35 BookmarkBarInstructionsView::BookmarkBarInstructionsView(
28 BookmarkBarInstructionsDelegate* delegate) 36 BookmarkBarInstructionsDelegate* delegate)
29 : delegate_(delegate), 37 : delegate_(delegate),
30 instructions_(NULL), 38 instructions_(NULL),
31 import_link_(NULL), 39 import_link_(NULL),
32 baseline_(-1), 40 baseline_(-1),
33 updated_colors_(false) { 41 updated_colors_(false) {
34 instructions_ = new views::Label( 42 instructions_ = new views::Label(
35 l10n_util::GetStringUTF16(IDS_BOOKMARKS_NO_ITEMS)); 43 l10n_util::GetStringUTF16(IDS_BOOKMARKS_NO_ITEMS));
36 instructions_->SetAutoColorReadabilityEnabled(false); 44 instructions_->SetAutoColorReadabilityEnabled(false);
45 instructions_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
Evan Stade 2015/10/22 21:52:12 the left align here and below fixes some jiggling
37 AddChildView(instructions_); 46 AddChildView(instructions_);
38 47
39 if (browser_defaults::kShowImportOnBookmarkBar) { 48 if (browser_defaults::kShowImportOnBookmarkBar) {
40 import_link_ = new views::Link( 49 import_link_ = new views::Link(
41 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_IMPORT_LINK)); 50 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_IMPORT_LINK));
42 // We don't want the link to alter tab navigation. 51 // We don't want the link to alter tab navigation.
43 import_link_->SetFocusable(false); 52 import_link_->SetFocusable(false);
44 import_link_->set_listener(this); 53 import_link_->set_listener(this);
45 import_link_->set_context_menu_controller(this); 54 import_link_->set_context_menu_controller(this);
46 import_link_->SetAutoColorReadabilityEnabled(false); 55 import_link_->SetAutoColorReadabilityEnabled(false);
56 import_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
47 AddChildView(import_link_); 57 AddChildView(import_link_);
48 } 58 }
49 } 59 }
50 60
51 gfx::Size BookmarkBarInstructionsView::GetPreferredSize() const { 61 gfx::Size BookmarkBarInstructionsView::GetPreferredSize() const {
52 int ascent = 0, descent = 0, height = 0, width = 0; 62 int ascent = 0, descent = 0, height = 0, width = 0;
53 for (int i = 0; i < child_count(); ++i) { 63 for (int i = 0; i < child_count(); ++i) {
54 const views::View* view = child_at(i); 64 const views::View* view = child_at(i);
55 gfx::Size pref = view->GetPreferredSize(); 65 gfx::Size pref = view->GetPreferredSize();
56 int baseline = view->GetBaseline(); 66 int baseline = view->GetBaseline();
57 if (baseline != -1) { 67 if (baseline != -1) {
58 ascent = std::max(ascent, baseline); 68 ascent = std::max(ascent, baseline);
59 descent = std::max(descent, pref.height() - baseline); 69 descent = std::max(descent, pref.height() - baseline);
60 } else { 70 } else {
61 height = std::max(pref.height(), height); 71 height = std::max(pref.height(), height);
62 } 72 }
63 width += pref.width(); 73 width += pref.width();
64 } 74 }
65 width += (child_count() - 1) * kViewPadding; 75 width += (child_count() - 1) * GetViewPadding();
66 if (ascent != 0) 76 if (ascent != 0)
67 height = std::max(ascent + descent, height); 77 height = std::max(ascent + descent, height);
68 return gfx::Size(width, height); 78 return gfx::Size(width, height);
69 } 79 }
70 80
71 void BookmarkBarInstructionsView::Layout() { 81 void BookmarkBarInstructionsView::Layout() {
72 int remaining_width = width(); 82 int remaining_width = width();
73 int x = 0; 83 int x = 0;
74 for (int i = 0; i < child_count(); ++i) { 84 for (int i = 0; i < child_count(); ++i) {
75 views::View* view = child_at(i); 85 views::View* view = child_at(i);
76 gfx::Size pref = view->GetPreferredSize(); 86 gfx::Size pref = view->GetPreferredSize();
77 int baseline = view->GetBaseline(); 87 int baseline = view->GetBaseline();
78 int y; 88 int y;
79 if (baseline != -1 && baseline_ != -1) 89 if (baseline != -1 && baseline_ != -1)
80 y = baseline_ - baseline; 90 y = baseline_ - baseline;
81 else 91 else
82 y = (height() - pref.height()) / 2; 92 y = (height() - pref.height()) / 2;
83 int view_width = std::min(remaining_width, pref.width()); 93 int view_width = std::min(remaining_width, pref.width());
84 view->SetBounds(x, y, view_width, pref.height()); 94 view->SetBounds(x, y, view_width, pref.height());
85 x += view_width + kViewPadding; 95 x += view_width + GetViewPadding();
86 remaining_width = std::max(0, width() - x); 96 remaining_width = std::max(0, width() - x);
87 } 97 }
88 } 98 }
89 99
90 const char* BookmarkBarInstructionsView::GetClassName() const { 100 const char* BookmarkBarInstructionsView::GetClassName() const {
91 return "BookmarkBarInstructionsView"; 101 return "BookmarkBarInstructionsView";
92 } 102 }
93 103
94 void BookmarkBarInstructionsView::OnThemeChanged() { 104 void BookmarkBarInstructionsView::OnThemeChanged() {
95 UpdateColors(); 105 UpdateColors();
(...skipping 25 matching lines...) Expand all
121 131
122 void BookmarkBarInstructionsView::UpdateColors() { 132 void BookmarkBarInstructionsView::UpdateColors() {
123 // We don't always have a theme provider (ui tests, for example). 133 // We don't always have a theme provider (ui tests, for example).
124 const ui::ThemeProvider* theme_provider = GetThemeProvider(); 134 const ui::ThemeProvider* theme_provider = GetThemeProvider();
125 if (!theme_provider) 135 if (!theme_provider)
126 return; 136 return;
127 updated_colors_ = true; 137 updated_colors_ = true;
128 SkColor text_color = 138 SkColor text_color =
129 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); 139 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
130 instructions_->SetEnabledColor(text_color); 140 instructions_->SetEnabledColor(text_color);
131 if (import_link_) 141 if (!import_link_)
142 return;
143
144 if (!ui::MaterialDesignController::IsModeMaterial()) {
132 import_link_->SetEnabledColor(text_color); 145 import_link_->SetEnabledColor(text_color);
146 } else {
147 // For MD, use the default link color if it provides enough contrast. If
148 // contrast is too low, fall back to the bookmark text color and use an
149 // underline to make it obvious it's a link. The default color readability
150 // code (which only adjusts luminance) doesn't work well in this case.
151 SkColor bg = theme_provider->GetColor(
152 ThemeProperties::ThemeProperties::COLOR_TOOLBAR);
153 SkColor link_color =
154 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled);
155 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >=
156 color_utils::kMinimumReadableContrastRatio;
157 import_link_->SetUnderline(!link_has_contrast);
158 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color);
159 }
133 } 160 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/search_ui.cc ('k') | chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698