Chromium Code Reviews| 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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 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 ascent = 0, descent = 0, 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 int baseline = view->GetBaseline(); |
|
Peter Kasting
2016/06/13 20:49:00
Does this code need changing too? Seems like it s
kylix_rd
2016/06/13 20:59:43
This code is merely for determining the preferred
Peter Kasting
2016/06/13 21:06:06
I'd simplify it as much as possible. Seems like y
kylix_rd
2016/06/13 21:17:20
Done.
| |
| 70 if (baseline != -1) { | 69 if (baseline != -1) { |
| 71 ascent = std::max(ascent, baseline); | 70 ascent = std::max(ascent, baseline); |
| 72 descent = std::max(descent, pref.height() - baseline); | 71 descent = std::max(descent, pref.height() - baseline); |
| 73 } else { | 72 } else { |
| 74 height = std::max(pref.height(), height); | 73 height = std::max(pref.height(), height); |
| 75 } | 74 } |
| 76 width += pref.width(); | 75 width += pref.width(); |
| 77 } | 76 } |
| 78 width += (child_count() - 1) * GetViewPadding(); | 77 width += (child_count() - 1) * GetViewPadding(); |
| 79 if (ascent != 0) | 78 if (ascent != 0) |
| 80 height = std::max(ascent + descent, height); | 79 height = std::max(ascent + descent, height); |
| 81 return gfx::Size(width, height); | 80 return gfx::Size(width, height); |
| 82 } | 81 } |
| 83 | 82 |
| 84 void BookmarkBarInstructionsView::Layout() { | 83 void BookmarkBarInstructionsView::Layout() { |
| 85 int remaining_width = width(); | 84 int remaining_width = width(); |
| 86 int x = 0; | 85 int x = 0; |
| 87 for (int i = 0; i < child_count(); ++i) { | 86 for (int i = 0; i < child_count(); ++i) { |
| 88 views::View* view = child_at(i); | 87 views::View* view = child_at(i); |
| 89 gfx::Size pref = view->GetPreferredSize(); | 88 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()); | 89 int view_width = std::min(remaining_width, pref.width()); |
| 97 view->SetBounds(x, y, view_width, pref.height()); | 90 view->SetBounds(x, 0, view_width, height()); |
|
Peter Kasting
2016/06/13 20:49:00
How does this look in the attached bookmark bar?
kylix_rd
2016/06/13 20:59:43
I'll admit that I'm not sure. How is attached vs.
Peter Kasting
2016/06/13 21:06:06
Toggle with ctrl-shift-b.
kylix_rd
2016/06/13 21:17:20
Ok, the alignment remains correct.
| |
| 98 x += view_width + GetViewPadding(); | 91 x += view_width + GetViewPadding(); |
| 99 remaining_width = std::max(0, width() - x); | 92 remaining_width = std::max(0, width() - x); |
| 100 } | 93 } |
| 101 } | 94 } |
| 102 | 95 |
| 103 const char* BookmarkBarInstructionsView::GetClassName() const { | 96 const char* BookmarkBarInstructionsView::GetClassName() const { |
| 104 return "BookmarkBarInstructionsView"; | 97 return "BookmarkBarInstructionsView"; |
| 105 } | 98 } |
| 106 | 99 |
| 107 void BookmarkBarInstructionsView::OnThemeChanged() { | 100 void BookmarkBarInstructionsView::OnThemeChanged() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 // code (which only adjusts luminance) doesn't work well in this case. | 146 // code (which only adjusts luminance) doesn't work well in this case. |
| 154 SkColor bg = theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR); | 147 SkColor bg = theme_provider->GetColor(ThemeProperties::COLOR_TOOLBAR); |
| 155 SkColor link_color = | 148 SkColor link_color = |
| 156 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); | 149 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); |
| 157 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >= | 150 bool link_has_contrast = color_utils::GetContrastRatio(link_color, bg) >= |
| 158 color_utils::kMinimumReadableContrastRatio; | 151 color_utils::kMinimumReadableContrastRatio; |
| 159 import_link_->SetUnderline(!link_has_contrast); | 152 import_link_->SetUnderline(!link_has_contrast); |
| 160 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color); | 153 import_link_->SetEnabledColor(link_has_contrast ? link_color : text_color); |
| 161 } | 154 } |
| 162 } | 155 } |
| OLD | NEW |