| OLD | NEW |
| 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/material_design/material_design_controller.h" | |
| 17 #include "ui/base/theme_provider.h" | 16 #include "ui/base/theme_provider.h" |
| 18 #include "ui/native_theme/native_theme.h" | 17 #include "ui/native_theme/native_theme.h" |
| 19 #include "ui/views/controls/label.h" | 18 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/controls/link.h" | 19 #include "ui/views/controls/link.h" |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 // Horizontal padding, in pixels, between the link and label. | 23 // Horizontal padding, in pixels, between the link and label. |
| 25 int GetViewPadding() { | 24 int GetViewPadding() { |
| 26 if (ui::MaterialDesignController::IsModeMaterial()) { | 25 static int space_width = |
| 27 static int space_width = | 26 views::Label(base::ASCIIToUTF16(" ")).GetPreferredSize().width(); |
| 28 views::Label(base::ASCIIToUTF16(" ")).GetPreferredSize().width(); | 27 return space_width; |
| 29 return space_width; | |
| 30 } | |
| 31 | |
| 32 // Pre-MD is hard-coded to 6px. | |
| 33 return 6; | |
| 34 } | 28 } |
| 35 | 29 |
| 36 } // namespace | 30 } // namespace |
| 37 | 31 |
| 38 BookmarkBarInstructionsView::BookmarkBarInstructionsView( | 32 BookmarkBarInstructionsView::BookmarkBarInstructionsView( |
| 39 BookmarkBarInstructionsDelegate* delegate) | 33 BookmarkBarInstructionsDelegate* delegate) |
| 40 : delegate_(delegate), | 34 : delegate_(delegate), |
| 41 instructions_(NULL), | 35 instructions_(NULL), |
| 42 import_link_(NULL), | 36 import_link_(NULL), |
| 43 updated_colors_(false) { | 37 updated_colors_(false) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 const ui::ThemeProvider* theme_provider = GetThemeProvider(); | 117 const ui::ThemeProvider* theme_provider = GetThemeProvider(); |
| 124 if (!theme_provider) | 118 if (!theme_provider) |
| 125 return; | 119 return; |
| 126 updated_colors_ = true; | 120 updated_colors_ = true; |
| 127 SkColor text_color = theme_provider->GetColor( | 121 SkColor text_color = theme_provider->GetColor( |
| 128 ThemeProperties::COLOR_BOOKMARK_BAR_INSTRUCTIONS_TEXT); | 122 ThemeProperties::COLOR_BOOKMARK_BAR_INSTRUCTIONS_TEXT); |
| 129 instructions_->SetEnabledColor(text_color); | 123 instructions_->SetEnabledColor(text_color); |
| 130 if (!import_link_) | 124 if (!import_link_) |
| 131 return; | 125 return; |
| 132 | 126 |
| 133 if (!ui::MaterialDesignController::IsModeMaterial()) { | 127 // Use the default link color if it provides enough contrast. If |
| 134 import_link_->SetEnabledColor(text_color); | 128 // contrast is too low, fall back to the bookmark text color and use an |
| 135 } else { | 129 // underline to make it obvious it's a link. The default color readability |
| 136 // For MD, use the default link color if it provides enough contrast. If | 130 // code (which only adjusts luminance) doesn't work well in this case. |
| 137 // contrast is too low, fall back to the bookmark text color and use an | 131 SkColor bg = theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR); |
| 138 // underline to make it obvious it's a link. The default color readability | 132 SkColor link_color = |
| 139 // code (which only adjusts luminance) doesn't work well in this case. | 133 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); |
| 140 SkColor bg = theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR); | 134 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >= |
| 141 SkColor link_color = | 135 color_utils::kMinimumReadableContrastRatio; |
| 142 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); | 136 import_link_->SetUnderline(!link_has_contrast); |
| 143 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >= | 137 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color); |
| 144 color_utils::kMinimumReadableContrastRatio; | |
| 145 import_link_->SetUnderline(!link_has_contrast); | |
| 146 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color); | |
| 147 } | |
| 148 } | 138 } |
| OLD | NEW |