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

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: eschew redundancy Created 5 years, 1 month 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 static int space_width =
28 views::Label(base::ASCIIToUTF16(" ")).GetPreferredSize().width();
29 return space_width;
30 }
31
32 // Pre-MD is hard-coded to 6px.
33 return 6;
34 }
24 35
25 } // namespace 36 } // namespace
26 37
27 BookmarkBarInstructionsView::BookmarkBarInstructionsView( 38 BookmarkBarInstructionsView::BookmarkBarInstructionsView(
28 BookmarkBarInstructionsDelegate* delegate) 39 BookmarkBarInstructionsDelegate* delegate)
29 : delegate_(delegate), 40 : delegate_(delegate),
30 instructions_(NULL), 41 instructions_(NULL),
31 import_link_(NULL), 42 import_link_(NULL),
32 baseline_(-1), 43 baseline_(-1),
33 updated_colors_(false) { 44 updated_colors_(false) {
34 instructions_ = new views::Label( 45 instructions_ = new views::Label(
35 l10n_util::GetStringUTF16(IDS_BOOKMARKS_NO_ITEMS)); 46 l10n_util::GetStringUTF16(IDS_BOOKMARKS_NO_ITEMS));
36 instructions_->SetAutoColorReadabilityEnabled(false); 47 instructions_->SetAutoColorReadabilityEnabled(false);
48 instructions_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
37 AddChildView(instructions_); 49 AddChildView(instructions_);
38 50
39 if (browser_defaults::kShowImportOnBookmarkBar) { 51 if (browser_defaults::kShowImportOnBookmarkBar) {
40 import_link_ = new views::Link( 52 import_link_ = new views::Link(
41 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_IMPORT_LINK)); 53 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_IMPORT_LINK));
42 // We don't want the link to alter tab navigation. 54 // We don't want the link to alter tab navigation.
43 import_link_->SetFocusable(false); 55 import_link_->SetFocusable(false);
44 import_link_->set_listener(this); 56 import_link_->set_listener(this);
45 import_link_->set_context_menu_controller(this); 57 import_link_->set_context_menu_controller(this);
46 import_link_->SetAutoColorReadabilityEnabled(false); 58 import_link_->SetAutoColorReadabilityEnabled(false);
59 import_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
47 AddChildView(import_link_); 60 AddChildView(import_link_);
48 } 61 }
49 } 62 }
50 63
51 gfx::Size BookmarkBarInstructionsView::GetPreferredSize() const { 64 gfx::Size BookmarkBarInstructionsView::GetPreferredSize() const {
52 int ascent = 0, descent = 0, height = 0, width = 0; 65 int ascent = 0, descent = 0, height = 0, width = 0;
53 for (int i = 0; i < child_count(); ++i) { 66 for (int i = 0; i < child_count(); ++i) {
54 const views::View* view = child_at(i); 67 const views::View* view = child_at(i);
55 gfx::Size pref = view->GetPreferredSize(); 68 gfx::Size pref = view->GetPreferredSize();
56 int baseline = view->GetBaseline(); 69 int baseline = view->GetBaseline();
57 if (baseline != -1) { 70 if (baseline != -1) {
58 ascent = std::max(ascent, baseline); 71 ascent = std::max(ascent, baseline);
59 descent = std::max(descent, pref.height() - baseline); 72 descent = std::max(descent, pref.height() - baseline);
60 } else { 73 } else {
61 height = std::max(pref.height(), height); 74 height = std::max(pref.height(), height);
62 } 75 }
63 width += pref.width(); 76 width += pref.width();
64 } 77 }
65 width += (child_count() - 1) * kViewPadding; 78 width += (child_count() - 1) * GetViewPadding();
66 if (ascent != 0) 79 if (ascent != 0)
67 height = std::max(ascent + descent, height); 80 height = std::max(ascent + descent, height);
68 return gfx::Size(width, height); 81 return gfx::Size(width, height);
69 } 82 }
70 83
71 void BookmarkBarInstructionsView::Layout() { 84 void BookmarkBarInstructionsView::Layout() {
72 int remaining_width = width(); 85 int remaining_width = width();
73 int x = 0; 86 int x = 0;
74 for (int i = 0; i < child_count(); ++i) { 87 for (int i = 0; i < child_count(); ++i) {
75 views::View* view = child_at(i); 88 views::View* view = child_at(i);
76 gfx::Size pref = view->GetPreferredSize(); 89 gfx::Size pref = view->GetPreferredSize();
77 int baseline = view->GetBaseline(); 90 int baseline = view->GetBaseline();
78 int y; 91 int y;
79 if (baseline != -1 && baseline_ != -1) 92 if (baseline != -1 && baseline_ != -1)
80 y = baseline_ - baseline; 93 y = baseline_ - baseline;
81 else 94 else
82 y = (height() - pref.height()) / 2; 95 y = (height() - pref.height()) / 2;
83 int view_width = std::min(remaining_width, pref.width()); 96 int view_width = std::min(remaining_width, pref.width());
84 view->SetBounds(x, y, view_width, pref.height()); 97 view->SetBounds(x, y, view_width, pref.height());
85 x += view_width + kViewPadding; 98 x += view_width + GetViewPadding();
86 remaining_width = std::max(0, width() - x); 99 remaining_width = std::max(0, width() - x);
87 } 100 }
88 } 101 }
89 102
90 const char* BookmarkBarInstructionsView::GetClassName() const { 103 const char* BookmarkBarInstructionsView::GetClassName() const {
91 return "BookmarkBarInstructionsView"; 104 return "BookmarkBarInstructionsView";
92 } 105 }
93 106
94 void BookmarkBarInstructionsView::OnThemeChanged() { 107 void BookmarkBarInstructionsView::OnThemeChanged() {
95 UpdateColors(); 108 UpdateColors();
(...skipping 25 matching lines...) Expand all
121 134
122 void BookmarkBarInstructionsView::UpdateColors() { 135 void BookmarkBarInstructionsView::UpdateColors() {
123 // We don't always have a theme provider (ui tests, for example). 136 // We don't always have a theme provider (ui tests, for example).
124 const ui::ThemeProvider* theme_provider = GetThemeProvider(); 137 const ui::ThemeProvider* theme_provider = GetThemeProvider();
125 if (!theme_provider) 138 if (!theme_provider)
126 return; 139 return;
127 updated_colors_ = true; 140 updated_colors_ = true;
128 SkColor text_color = 141 SkColor text_color =
129 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); 142 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
130 instructions_->SetEnabledColor(text_color); 143 instructions_->SetEnabledColor(text_color);
131 if (import_link_) 144 if (!import_link_)
145 return;
146
147 if (!ui::MaterialDesignController::IsModeMaterial()) {
132 import_link_->SetEnabledColor(text_color); 148 import_link_->SetEnabledColor(text_color);
149 } else {
150 // For MD, use the default link color if it provides enough contrast. If
151 // contrast is too low, fall back to the bookmark text color and use an
152 // underline to make it obvious it's a link. The default color readability
153 // code (which only adjusts luminance) doesn't work well in this case.
154 SkColor bg = theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR);
155 SkColor link_color =
156 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled);
157 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >=
158 color_utils::kMinimumReadableContrastRatio;
159 import_link_->SetUnderline(!link_has_contrast);
160 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color);
161 }
133 } 162 }
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