diff options
73 files changed, 1031 insertions, 998 deletions
diff --git a/chrome/browser/chromeos/drop_shadow_label.cc b/chrome/browser/chromeos/drop_shadow_label.cc index 88c36e2..5be5e93 100644 --- a/chrome/browser/chromeos/drop_shadow_label.cc +++ b/chrome/browser/chromeos/drop_shadow_label.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -14,17 +14,7 @@ namespace chromeos { static const int kDefaultDropShadowSize = 2; -// Default color is black. -static const SkColor kDefaultColor = 0x000000; - -static const float kShadowOpacity = 0.2; - -DropShadowLabel::DropShadowLabel() : Label() { - Init(); -} - -void DropShadowLabel::Init() { - drop_shadow_size_ = kDefaultDropShadowSize; +DropShadowLabel::DropShadowLabel() : drop_shadow_size_(kDefaultDropShadowSize) { } void DropShadowLabel::SetDropShadowSize(int drop_shadow_size) { @@ -39,27 +29,26 @@ void DropShadowLabel::PaintText(gfx::Canvas* canvas, const string16& text, const gfx::Rect& text_bounds, int flags) { + SkColor text_color = IsEnabled() ? enabled_color() : disabled_color(); if (drop_shadow_size_ > 0) { - SkColor color = SkColorSetARGB(kShadowOpacity * SkColorGetA(GetColor()), - SkColorGetR(kDefaultColor), - SkColorGetG(kDefaultColor), - SkColorGetB(kDefaultColor)); + const float kShadowOpacity = 0.2; + const SkColor shadow_color = + SkColorSetA(SK_ColorBLACK, kShadowOpacity * SkColorGetA(text_color)); for (int i = 0; i < drop_shadow_size_; i++) { - canvas->DrawStringInt(text, font(), color, + canvas->DrawStringInt(text, font(), shadow_color, text_bounds.x() + i, text_bounds.y(), text_bounds.width(), text_bounds.height(), flags); - canvas->DrawStringInt(text, font(), color, + canvas->DrawStringInt(text, font(), shadow_color, text_bounds.x() + i, text_bounds.y() + i, text_bounds.width(), text_bounds.height(), flags); - canvas->DrawStringInt(text, font(), color, + canvas->DrawStringInt(text, font(), shadow_color, text_bounds.x(), text_bounds.y() + i, text_bounds.width(), text_bounds.height(), flags); } } - canvas->DrawStringInt(text, font(), GetColor(), - text_bounds.x(), text_bounds.y(), - text_bounds.width(), text_bounds.height(), flags); + canvas->DrawStringInt(text, font(), text_color, text_bounds.x(), + text_bounds.y(), text_bounds.width(), text_bounds.height(), flags); if (HasFocus() || paint_as_focused()) { gfx::Rect focus_bounds = text_bounds; diff --git a/chrome/browser/chromeos/drop_shadow_label.h b/chrome/browser/chromeos/drop_shadow_label.h index f17c499..1be105d 100644 --- a/chrome/browser/chromeos/drop_shadow_label.h +++ b/chrome/browser/chromeos/drop_shadow_label.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -44,8 +44,6 @@ class DropShadowLabel : public views::Label { virtual gfx::Size GetTextSize() const OVERRIDE; private: - void Init(); - int drop_shadow_size_; DISALLOW_COPY_AND_ASSIGN(DropShadowLabel); diff --git a/chrome/browser/chromeos/frame/panel_controller.cc b/chrome/browser/chromeos/frame/panel_controller.cc index a137076..174d67a 100644 --- a/chrome/browser/chromeos/frame/panel_controller.cc +++ b/chrome/browser/chromeos/frame/panel_controller.cc @@ -241,11 +241,9 @@ void PanelController::SetUrgent(bool urgent) { urgent_ = urgent; if (title_window_) { gtk_window_set_urgency_hint(panel_, urgent ? TRUE : FALSE); + title_content_->title_label()->SetDisabledColor(urgent ? + kTitleUrgentTextColor : kTitleInactiveTextColor); title_content_->SchedulePaint(); - if (urgent) - title_content_->title_label()->SetColor(kTitleUrgentTextColor); - else - title_content_->title_label()->SetColor(kTitleInactiveTextColor); } } @@ -452,6 +450,10 @@ PanelController::TitleContentView::TitleContentView( AddChildView(title_icon_); title_label_ = new views::Label(string16()); title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + title_label_->SetAutoColorReadabilityEnabled(false); + title_label_->SetEnabledColor(kTitleActiveTextColor); + title_label_->SetDisabledColor(kTitleInactiveTextColor); + title_label_->SetEnabled(false); AddChildView(title_label_); set_background( @@ -501,14 +503,14 @@ bool PanelController::TitleContentView::OnMouseDragged( } void PanelController::TitleContentView::OnFocusIn() { - title_label_->SetColor(kTitleActiveTextColor); + title_label_->SetEnabled(true); title_label_->SetFont(*active_font); Layout(); SchedulePaint(); } void PanelController::TitleContentView::OnFocusOut() { - title_label_->SetColor(kTitleInactiveTextColor); + title_label_->SetEnabled(false); title_label_->SetFont(*inactive_font); Layout(); SchedulePaint(); diff --git a/chrome/browser/chromeos/input_method/candidate_window.cc b/chrome/browser/chromeos/input_method/candidate_window.cc index 2ea6805..551ba32 100644 --- a/chrome/browser/chromeos/input_method/candidate_window.cc +++ b/chrome/browser/chromeos/input_method/candidate_window.cc @@ -119,26 +119,20 @@ views::View* WrapWithPadding(views::View* view, const gfx::Insets& insets) { } // Creates shortcut text from the given index and the orientation. -std::wstring CreateShortcutText( - int index, - InputMethodLookupTable::Orientation orientation) { +string16 CreateShortcutText(int index, + InputMethodLookupTable::Orientation orientation) { // Choose the character used for the shortcut label. - const wchar_t kShortcutCharacters[] = L"1234567890ABCDEF"; + const char kShortcutCharacters[] = "1234567890ABCDEF"; // The default character should not be used but just in case. - wchar_t shortcut_character = L'?'; + char shortcut_character = L'?'; // -1 to exclude the null character at the end. - if (index < static_cast<int>(arraysize(kShortcutCharacters) - 1)) { + if (index < static_cast<int>(arraysize(kShortcutCharacters) - 1)) shortcut_character = kShortcutCharacters[index]; - } - - std::wstring shortcut_text; - if (orientation == InputMethodLookupTable::kVertical) { - shortcut_text = base::StringPrintf(L"%lc", shortcut_character); - } else { - shortcut_text = base::StringPrintf(L"%lc.", shortcut_character); - } - return shortcut_text; + std::string shortcut_text(1, shortcut_character); + if (orientation != InputMethodLookupTable::kVertical) + shortcut_text += '.'; + return ASCIIToUTF16(shortcut_text); } // Creates the shortcut label, and returns it (never returns NULL). @@ -159,7 +153,8 @@ views::Label* CreateShortcutLabel( } // TODO(satorux): Maybe we need to use language specific fonts for // candidate_label, like Chinese font for Chinese input method? - shortcut_label->SetColor(kShortcutColor); + shortcut_label->SetEnabledColor(kShortcutColor); + shortcut_label->SetDisabledColor(kDisabledShortcutColor); return shortcut_label; } @@ -186,6 +181,8 @@ views::View* CreateWrappedShortcutLabel( wrapped_shortcut_label->set_background( views::Background::CreateSolidBackground( kShortcutBackgroundColor)); + shortcut_label->SetBackgroundColor( + wrapped_shortcut_label->background()->get_color()); } return wrapped_shortcut_label; @@ -223,7 +220,7 @@ views::Label* CreateAnnotationLabel( // Change the font size and color. annotation_label->SetFont( annotation_label->font().DeriveFont(kFontSizeDelta)); - annotation_label->SetColor(kAnnotationColor); + annotation_label->SetEnabledColor(kAnnotationColor); annotation_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); return annotation_label; @@ -243,8 +240,7 @@ int ComputeShortcutColumnWidth( // Compute the max width in shortcut labels. // We'll create temporary shortcut labels, and choose the largest width. for (int i = 0; i < lookup_table.page_size; ++i) { - shortcut_label->SetText( - WideToUTF16Hack(CreateShortcutText(i, lookup_table.orientation))); + shortcut_label->SetText(CreateShortcutText(i, lookup_table.orientation)); shortcut_column_width = std::max(shortcut_column_width, wrapped_shortcut_label->GetPreferredSize().width()); @@ -392,6 +388,7 @@ class InformationTextArea : public HidableArea { views::Background::CreateVerticalGradientBackground( kFooterTopColor, kFooterBottomColor)); + label_->SetBackgroundColor(contents->background()->get_color()); } // Set the displayed text. @@ -596,13 +593,13 @@ class CandidateView : public views::View { int annotation_column_width); // Sets candidate text to the given text. - void SetCandidateText(const std::wstring& text); + void SetCandidateText(const string16& text); // Sets shortcut text to the given text. - void SetShortcutText(const std::wstring& text); + void SetShortcutText(const string16& text); // Sets annotation text to the given text. - void SetAnnotationText(const std::wstring& text); + void SetAnnotationText(const string16& text); // Sets infolist icon. void SetInfolistIcon(bool enable); @@ -626,6 +623,10 @@ class CandidateView : public views::View { // Overridden from View: virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + // Notifies labels of their new background colors. Called whenever the view's + // background color changes. + void UpdateLabelBackgroundColors(); + // Zero-origin index in the current page. int index_in_page_; @@ -655,8 +656,8 @@ class InfolistView; // InfolistWindowView is the main container of the infolist window UI. class InfolistWindowView : public views::View { public: - InfolistWindowView( - views::Widget* parent_frame, views::Widget* candidate_window_frame); + InfolistWindowView(views::Widget* parent_frame, + views::Widget* candidate_window_frame); virtual ~InfolistWindowView(); void Init(); void Show(); @@ -722,6 +723,10 @@ class InfolistView : public views::View { void Unselect(); private: + // Notifies labels of their new background colors. Called whenever the view's + // background color changes. + void UpdateLabelBackgroundColors(); + // The parent candidate window that contains this view. InfolistWindowView* parent_infolist_window_; @@ -861,40 +866,36 @@ void CandidateView::Init(int shortcut_column_width, layout->AddView(WrapWithPadding(infolist_label_, gfx::Insets(2, 0, 2, 0))); } + UpdateLabelBackgroundColors(); } -void CandidateView::SetCandidateText(const std::wstring& text) { - candidate_label_->SetText(WideToUTF16Hack(text)); +void CandidateView::SetCandidateText(const string16& text) { + candidate_label_->SetText(text); } -void CandidateView::SetShortcutText(const std::wstring& text) { - shortcut_label_->SetText(WideToUTF16Hack(text)); +void CandidateView::SetShortcutText(const string16& text) { + shortcut_label_->SetText(text); } -void CandidateView::SetAnnotationText(const std::wstring& text) { - annotation_label_->SetText(WideToUTF16Hack(text)); +void CandidateView::SetAnnotationText(const string16& text) { + annotation_label_->SetText(text); } void CandidateView::SetInfolistIcon(bool enable) { - if (!infolist_label_) { + if (!infolist_label_ || (infolist_icon_enabled_ == enable)) return; - } - if (enable) { - infolist_label_->set_background( - views::Background::CreateSolidBackground(kSelectedRowFrameColor)); - } else { - infolist_label_->set_background(NULL); - } - if (infolist_icon_enabled_ != enable) { - SchedulePaint(); - } infolist_icon_enabled_ = enable; + infolist_label_->set_background(enable ? + views::Background::CreateSolidBackground(kSelectedRowFrameColor) : NULL); + UpdateLabelBackgroundColors(); + SchedulePaint(); } void CandidateView::Select() { set_background( views::Background::CreateSolidBackground(kSelectedRowBackgroundColor)); set_border(views::Border::CreateSolidBorder(1, kSelectedRowFrameColor)); + UpdateLabelBackgroundColors(); // Need to call SchedulePaint() for background and border color changes. SchedulePaint(); } @@ -902,12 +903,12 @@ void CandidateView::Select() { void CandidateView::Unselect() { set_background(NULL); set_border(NULL); + UpdateLabelBackgroundColors(); SchedulePaint(); // See comments at Select(). } void CandidateView::SetRowEnabled(bool enabled) { - shortcut_label_->SetColor( - enabled ? kShortcutColor : kDisabledShortcutColor); + shortcut_label_->SetEnabled(enabled); } gfx::Point CandidateView::GetCandidateLabelPosition() const { @@ -957,8 +958,20 @@ bool CandidateView::OnMousePressed(const views::MouseEvent& event) { return false; } -CandidateWindowView::CandidateWindowView( - views::Widget* parent_frame) +void CandidateView::UpdateLabelBackgroundColors() { + SkColor color = background() ? + background()->get_color() : kDefaultBackgroundColor; + if (orientation_ != InputMethodLookupTable::kVertical) + shortcut_label_->SetBackgroundColor(color); + candidate_label_->SetBackgroundColor(color); + annotation_label_->SetBackgroundColor(color); + if (infolist_label_) { + infolist_label_->SetBackgroundColor(infolist_label_->background() ? + infolist_label_->background()->get_color() : color); + } +} + +CandidateWindowView::CandidateWindowView(views::Widget* parent_frame) : selected_candidate_index_in_page_(0), parent_frame_(parent_frame), preedit_area_(NULL), @@ -1105,14 +1118,14 @@ void CandidateWindowView::UpdateCandidates( // case, we should not show shortcut labels. const bool no_shortcut_mode = (start_from < new_lookup_table.labels.size() && - new_lookup_table.labels[start_from] == ""); + new_lookup_table.labels[start_from].empty()); for (size_t i = 0; i < candidate_views_.size(); ++i) { const size_t index_in_page = i; const size_t candidate_index = start_from + index_in_page; CandidateView* candidate_view = candidate_views_[index_in_page]; // Set the shortcut text. if (no_shortcut_mode) { - candidate_view->SetShortcutText(L""); + candidate_view->SetShortcutText(string16()); } else { // At this moment, we don't use labels sent from engines for UX // reasons. First, we want to show shortcut labels in empty rows @@ -1126,9 +1139,9 @@ void CandidateWindowView::UpdateCandidates( if (candidate_index < new_lookup_table.candidates.size() && candidate_index < new_lookup_table.annotations.size()) { candidate_view->SetCandidateText( - UTF8ToWide(new_lookup_table.candidates[candidate_index])); + UTF8ToUTF16(new_lookup_table.candidates[candidate_index])); candidate_view->SetAnnotationText( - UTF8ToWide(new_lookup_table.annotations[candidate_index])); + UTF8ToUTF16(new_lookup_table.annotations[candidate_index])); candidate_view->SetRowEnabled(true); if ((new_lookup_table.mozc_candidates.candidate_size() > @@ -1141,8 +1154,8 @@ void CandidateWindowView::UpdateCandidates( } } else { // Disable the empty row. - candidate_view->SetCandidateText(L""); - candidate_view->SetAnnotationText(L""); + candidate_view->SetCandidateText(string16()); + candidate_view->SetAnnotationText(string16()); candidate_view->SetRowEnabled(false); candidate_view->SetInfolistIcon(false); } @@ -1412,6 +1425,7 @@ void InfolistView::Init() { layout->AddView(wrapped_title_label); layout->StartRow(0, 0); layout->AddView(wrapped_description_label); + UpdateLabelBackgroundColors(); } @@ -1424,11 +1438,11 @@ void InfolistView::SetDescriptionText(const std::wstring& text) { } void InfolistView::Select() { - set_background( - views::Background::CreateSolidBackground( - kSelectedInfolistRowBackgroundColor)); + set_background(views::Background::CreateSolidBackground( + kSelectedInfolistRowBackgroundColor)); set_border( views::Border::CreateSolidBorder(1, kSelectedInfolistRowFrameColor)); + UpdateLabelBackgroundColors(); // Need to call SchedulePaint() for background and border color changes. SchedulePaint(); } @@ -1436,11 +1450,19 @@ void InfolistView::Select() { void InfolistView::Unselect() { set_background(NULL); set_border(NULL); + UpdateLabelBackgroundColors(); SchedulePaint(); // See comments at Select(). } -InfolistWindowView::InfolistWindowView( - views::Widget* parent_frame, views::Widget* candidate_window_frame) +void InfolistView::UpdateLabelBackgroundColors() { + SkColor color = background() ? + background()->get_color() : kDefaultBackgroundColor; + title_label_->SetBackgroundColor(color); + description_label_->SetBackgroundColor(color); +} + +InfolistWindowView::InfolistWindowView(views::Widget* parent_frame, + views::Widget* candidate_window_frame) : parent_frame_(parent_frame), candidate_window_frame_(candidate_window_frame), infolist_area_(NULL), @@ -1484,6 +1506,8 @@ void InfolistWindowView::Init() { WrapWithPadding(caption_label, gfx::Insets(2, 2, 2, 2)); wrapped_caption_label->set_background( views::Background::CreateSolidBackground(kInfolistTitleBackgroundColor)); + caption_label->SetBackgroundColor( + wrapped_caption_label->background()->get_color()); layout->AddView(wrapped_caption_label); layout->StartRow(0, 0); diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc index 40b2327..e07b659 100644 --- a/chrome/browser/chromeos/login/background_view.cc +++ b/chrome/browser/chromeos/login/background_view.cc @@ -345,7 +345,8 @@ void BackgroundView::InitInfoLabels() { delete os_version_label_; os_version_label_ = new views::Label(); os_version_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - os_version_label_->SetColor(kVersionColor); + os_version_label_->SetEnabledColor(kVersionColor); + os_version_label_->SetBackgroundColor(background()->get_color()); os_version_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); if (idx < 0) AddChildView(os_version_label_); @@ -357,7 +358,8 @@ void BackgroundView::InitInfoLabels() { delete boot_times_label_; boot_times_label_ = new views::Label(); boot_times_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - boot_times_label_->SetColor(kVersionColor); + boot_times_label_->SetEnabledColor(kVersionColor); + boot_times_label_->SetBackgroundColor(background()->get_color()); boot_times_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); if (idx < 0) AddChildView(boot_times_label_); diff --git a/chrome/browser/chromeos/login/message_bubble.cc b/chrome/browser/chromeos/login/message_bubble.cc index 022ec9b..074494ff 100644 --- a/chrome/browser/chromeos/login/message_bubble.cc +++ b/chrome/browser/chromeos/login/message_bubble.cc @@ -66,6 +66,7 @@ MessageBubble::MessageBubble(views::Widget::InitParams::Type type, text_ = new views::Label(WideToUTF16Hack(text)); text_->SetMultiLine(true); text_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + text_->SetBackgroundColor(Bubble::kBackgroundColor); text_->SizeToFit(kMaxLabelWidth); layout->AddView(text_); @@ -83,8 +84,9 @@ MessageBubble::MessageBubble(views::Widget::InitParams::Type type, views::Link* help_link_ = new views::Link(WideToUTF16Hack(links[i])); help_links_.push_back(help_link_); help_link_->set_listener(this); - help_link_->SetNormalColor(login::kLinkColor); - help_link_->SetHighlightedColor(login::kLinkColor); + help_link_->SetBackgroundColor(Bubble::kBackgroundColor); + help_link_->SetEnabledColor(login::kLinkColor); + help_link_->SetPressedColor(login::kLinkColor); layout->AddView(help_link_); } } diff --git a/chrome/browser/chromeos/login/network_selection_view.cc b/chrome/browser/chromeos/login/network_selection_view.cc index e3eb0c5..1b05732 100644 --- a/chrome/browser/chromeos/login/network_selection_view.cc +++ b/chrome/browser/chromeos/login/network_selection_view.cc @@ -23,6 +23,7 @@ #include "grit/theme_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/color_utils.h" #include "ui/gfx/size.h" #include "views/controls/label.h" #include "views/controls/link.h" @@ -289,18 +290,24 @@ void NetworkSelectionView::Init() { &BorderDefinition::kScreenBorder); contents_view_->set_background( views::Background::CreateBackgroundPainter(true, painter)); + SkColor background_color = color_utils::AlphaBlend( + BorderDefinition::kScreenBorder.top_color, + BorderDefinition::kScreenBorder.bottom_color, 128); welcome_label_ = new views::Label(); - welcome_label_->SetColor(kWelcomeColor); + welcome_label_->SetEnabledColor(kWelcomeColor); + welcome_label_->SetBackgroundColor(background_color); welcome_label_->SetMultiLine(true); select_language_label_ = new views::Label(); + select_language_label_->SetBackgroundColor(background_color); languages_menubutton_ = new NotifyingMenuButton( NULL, std::wstring(), actor_->language_switch_menu(), true, actor_); InitMenuButtonProperties(languages_menubutton_); select_keyboard_label_ = new views::Label(); + select_keyboard_label_->SetBackgroundColor(background_color); keyboards_menubutton_ = new DropDownButton( NULL /* listener */, L"", actor_->keyboard_switch_menu(), @@ -308,6 +315,7 @@ void NetworkSelectionView::Init() { InitMenuButtonProperties(keyboards_menubutton_); select_network_label_ = new views::Label(); + select_network_label_->SetBackgroundColor(background_color); network_dropdown_ = new NetworkControlReportOnActivate(false, GetNativeWindow(), @@ -315,14 +323,16 @@ void NetworkSelectionView::Init() { InitMenuButtonProperties(network_dropdown_); connecting_network_label_ = new views::Label(); + connecting_network_label_->SetBackgroundColor(background_color); connecting_network_label_->SetVisible(false); proxy_settings_link_ = new views::Link(); proxy_settings_link_->set_listener(this); proxy_settings_link_->SetVisible(true); proxy_settings_link_->set_focusable(true); - proxy_settings_link_->SetNormalColor(login::kLinkColor); - proxy_settings_link_->SetHighlightedColor(login::kLinkColor); + proxy_settings_link_->SetBackgroundColor(background_color); + proxy_settings_link_->SetEnabledColor(login::kLinkColor); + proxy_settings_link_->SetPressedColor(login::kLinkColor); UpdateLocalizedStringsAndFonts(); } diff --git a/chrome/browser/chromeos/login/new_user_view.cc b/chrome/browser/chromeos/login/new_user_view.cc index afb2ac2..9271fc3 100644 --- a/chrome/browser/chromeos/login/new_user_view.cc +++ b/chrome/browser/chromeos/login/new_user_view.cc @@ -32,6 +32,7 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/color_utils.h" #include "ui/gfx/font.h" #include "views/controls/button/menu_button.h" #include "views/controls/button/text_button.h" @@ -103,9 +104,7 @@ class UsernameField : public chromeos::TextfieldWithMargin { namespace chromeos { -NewUserView::NewUserView(Delegate* delegate, - bool need_border, - bool need_guest_link) +NewUserView::NewUserView(Delegate* delegate, bool need_guest_link) : username_field_(NULL), password_field_(NULL), title_label_(NULL), @@ -126,7 +125,6 @@ NewUserView::NewUserView(Delegate* delegate, delegate_(delegate), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), login_in_process_(false), - need_border_(need_border), need_guest_link_(false), need_create_account_(false), languages_menubutton_order_(-1), @@ -142,22 +140,24 @@ NewUserView::~NewUserView() { } void NewUserView::Init() { - if (need_border_) { - // Use rounded rect background. - set_border(CreateWizardBorder(&BorderDefinition::kUserBorder)); - views::Painter* painter = CreateWizardPainter( - &BorderDefinition::kUserBorder); - set_background(views::Background::CreateBackgroundPainter(true, painter)); - } + // Use rounded rect background. + set_border(CreateWizardBorder(&BorderDefinition::kUserBorder)); + views::Painter* painter = CreateWizardPainter(&BorderDefinition::kUserBorder); + set_background(views::Background::CreateBackgroundPainter(true, painter)); + SkColor background_color = color_utils::AlphaBlend( + BorderDefinition::kUserBorder.top_color, + BorderDefinition::kUserBorder.bottom_color, 128); title_label_ = new views::Label(); + title_label_->SetBackgroundColor(background_color); title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); title_label_->SetMultiLine(true); AddChildView(title_label_); title_hint_label_ = new views::Label(); + title_hint_label_->SetBackgroundColor(background_color); title_hint_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - title_hint_label_->SetColor(SK_ColorGRAY); + title_hint_label_->SetEnabledColor(SK_ColorGRAY); title_hint_label_->SetMultiLine(true); AddChildView(title_hint_label_); @@ -181,12 +181,10 @@ void NewUserView::Init() { RecreatePeculiarControls(); AddChildView(sign_in_button_); - if (need_guest_link_) { - InitLink(&guest_link_); - } - if (need_create_account_) { - InitLink(&create_account_link_); - } + if (need_guest_link_) + guest_link_ = InitLink(background_color); + if (need_create_account_) + create_account_link_ = InitLink(background_color); AddChildView(languages_menubutton_); // Set up accelerators. @@ -561,21 +559,21 @@ void NewUserView::EnableInputControls(bool enabled) { } bool NewUserView::NavigateAway() { - if (username_field_->text().empty() && - password_field_->text().empty()) { - delegate_->NavigateAway(); - return true; - } else { + if (!username_field_->text().empty() || + !password_field_->text().empty()) return false; - } + delegate_->NavigateAway(); + return true; } -void NewUserView::InitLink(views::Link** link) { - *link = new views::Link(string16()); - (*link)->set_listener(this); - (*link)->SetNormalColor(login::kLinkColor); - (*link)->SetHighlightedColor(login::kLinkColor); - AddChildView(*link); +views::Link* NewUserView::InitLink(SkColor background_color) { + views::Link* link = new views::Link(string16()); + link->set_listener(this); + link->SetBackgroundColor(background_color); + link->SetEnabledColor(login::kLinkColor); + link->SetPressedColor(login::kLinkColor); + AddChildView(link); + return link; } } // namespace chromeos diff --git a/chrome/browser/chromeos/login/new_user_view.h b/chrome/browser/chromeos/login/new_user_view.h index a68fead..c8537e4 100644 --- a/chrome/browser/chromeos/login/new_user_view.h +++ b/chrome/browser/chromeos/login/new_user_view.h @@ -60,10 +60,7 @@ class NewUserView : public ThrobberHostView, virtual void NavigateAway() = 0; }; - // If |need_border| is true, RoundedRect border and background are required. - NewUserView(Delegate* delegate, - bool need_border, - bool need_guest_link); + NewUserView(Delegate* delegate, bool need_guest_link); virtual ~NewUserView(); @@ -129,7 +126,7 @@ class NewUserView : public ThrobberHostView, private: // Creates Link control and adds it as a child. - void InitLink(views::Link** link); + views::Link* InitLink(SkColor background_color); // Delete and recreate native controls that fail to update preferred size // after text/locale update. @@ -176,9 +173,6 @@ class NewUserView : public ThrobberHostView, // True when login is in process. bool login_in_process_; - // If true, this view needs RoundedRect border and background. - bool need_border_; - // Whether Guest Mode link is needed. bool need_guest_link_; diff --git a/chrome/browser/chromeos/login/screen_lock_view.cc b/chrome/browser/chromeos/login/screen_lock_view.cc index f345a71..900a9ac 100644 --- a/chrome/browser/chromeos/login/screen_lock_view.cc +++ b/chrome/browser/chromeos/login/screen_lock_view.cc @@ -152,7 +152,8 @@ void ScreenLockView::Init() { UsernameView* username = UsernameView::CreateShapedUsernameView(UTF8ToWide(display_name), false); username_ = username; - username->SetColor(login::kTextColor); + username->SetEnabledColor(login::kTextColor); + username->SetBackgroundColor(main_->background()->get_color()); username->SetFont(font); // Add tooltip if screen name is not unique. diff --git a/chrome/browser/chromeos/login/update_view.cc b/chrome/browser/chromeos/login/update_view.cc index 1834be5..12a7c85 100644 --- a/chrome/browser/chromeos/login/update_view.cc +++ b/chrome/browser/chromeos/login/update_view.cc @@ -16,6 +16,7 @@ #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/color_utils.h" #include "views/border.h" #include "views/controls/label.h" #include "views/controls/progress_bar.h" @@ -79,27 +80,30 @@ void UpdateView::Init() { views::Painter* painter = chromeos::CreateWizardPainter( &chromeos::BorderDefinition::kScreenBorder); set_background(views::Background::CreateBackgroundPainter(true, painter)); + SkColor background_color = color_utils::AlphaBlend( + BorderDefinition::kScreenBorder.top_color, + BorderDefinition::kScreenBorder.bottom_color, 128); - InitLabel(&installing_updates_label_); - InitLabel(&preparing_updates_label_); - InitLabel(&reboot_label_); - InitLabel(&manual_reboot_label_); + installing_updates_label_ = InitLabel(background_color); + preparing_updates_label_ = InitLabel(background_color); preparing_updates_label_->SetVisible(false); + reboot_label_ = InitLabel(background_color); + manual_reboot_label_ = InitLabel(background_color); manual_reboot_label_->SetVisible(false); - manual_reboot_label_->SetColor(kManualRebootLabelColor); + manual_reboot_label_->SetEnabledColor(kManualRebootLabelColor); progress_bar_ = new views::ProgressBar(); AddChildView(progress_bar_); progress_bar_->SetDisplayRange(0.0, 100.0); // Curtain view. - InitLabel(&checking_label_); + checking_label_ = InitLabel(background_color); throbber_ = CreateDefaultThrobber(); AddChildView(throbber_); #if !defined(OFFICIAL_BUILD) - InitLabel(&escape_to_skip_label_); - escape_to_skip_label_->SetColor(kSkipLabelColor); + escape_to_skip_label_ = InitLabel(background_color); + escape_to_skip_label_->SetEnabledColor(kSkipLabelColor); escape_to_skip_label_->SetText( ASCIIToUTF16("Press ESCAPE to skip (Non-official builds only)")); #endif @@ -214,17 +218,19 @@ void UpdateView::Layout() { SchedulePaint(); } -void UpdateView::InitLabel(views::Label** label) { - *label = new views::Label(); - (*label)->SetColor(kLabelColor); - (*label)->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - (*label)->SetMultiLine(true); +views::Label* UpdateView::InitLabel(SkColor background_color) { + views::Label* label = new views::Label(); + label->SetBackgroundColor(background_color); + label->SetEnabledColor(kLabelColor); + label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + label->SetMultiLine(true); ResourceBundle& res_bundle = ResourceBundle::GetSharedInstance(); gfx::Font label_font = res_bundle.GetFont(ResourceBundle::MediumFont); - (*label)->SetFont(label_font); + label->SetFont(label_font); - AddChildView(*label); + AddChildView(label); + return label; } void UpdateView::UpdateVisibility() { diff --git a/chrome/browser/chromeos/login/update_view.h b/chrome/browser/chromeos/login/update_view.h index e6551e5..128b1e7 100644 --- a/chrome/browser/chromeos/login/update_view.h +++ b/chrome/browser/chromeos/login/update_view.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_CHROMEOS_LOGIN_UPDATE_VIEW_H_ #pragma once +#include "third_party/skia/include/core/SkColor.h" #include "views/view.h" namespace views { @@ -50,7 +51,7 @@ class UpdateView : public views::View { private: // Creates Label control and adds it as a child. - void InitLabel(views::Label** label); + views::Label* InitLabel(SkColor background_color); // Updates visibility of the elements. void UpdateVisibility(); diff --git a/chrome/browser/chromeos/login/user_controller.cc b/chrome/browser/chromeos/login/user_controller.cc index b88ea60..ce6194b 100644 --- a/chrome/browser/chromeos/login/user_controller.cc +++ b/chrome/browser/chromeos/login/user_controller.cc @@ -367,7 +367,7 @@ void UserController::SetupControlsWidget( views::View* control_view; if (is_new_user_) { NewUserView* new_user_view = - new NewUserView(this, true, need_browse_without_signin); + new NewUserView(this, need_browse_without_signin); new_user_view->Init(); control_view = new_user_view; user_input_ = new_user_view; @@ -491,7 +491,8 @@ Widget* UserController::CreateLabelWidget(int index, WmIpcWindowType type) { const gfx::Font& font = (type == WM_IPC_WINDOW_LOGIN_LABEL) ? GetLabelFont() : GetUnselectedLabelFont(); label->SetFont(font); - label->SetColor(login::kTextColor); + label->SetAutoColorReadabilityEnabled(false); + label->SetEnabledColor(login::kTextColor); if (type == WM_IPC_WINDOW_LOGIN_LABEL) label_view_ = label; diff --git a/chrome/browser/chromeos/login/user_view.cc b/chrome/browser/chromeos/login/user_view.cc index 5ebf44f..e59a7f9 100644 --- a/chrome/browser/chromeos/login/user_view.cc +++ b/chrome/browser/chromeos/login/user_view.cc @@ -24,12 +24,10 @@ #include "views/controls/label.h" #include "views/controls/link.h" #include "views/controls/link_listener.h" -#include "views/painter.h" namespace { -// Background color and corner radius of the login status label and -// signout button. +// Background color of the signout button. const SkColor kSignoutBackgroundColor = 0xFF007700; // Horiz/Vert insets for Signout view. @@ -43,21 +41,6 @@ const SkColor kImageBorderColor = 0xFFCCCCCC; // Padding between remove button and top right image corner. const int kRemoveButtonPadding = 3; -// Draws green-ish background for signout view with -// rounded corners at the bottom. -class SignoutBackgroundPainter : public views::Painter { - virtual void Paint(int w, int h, gfx::Canvas* canvas) { - SkRect rect = {0, 0, w, h}; - SkPath path; - path.addRect(rect); - SkPaint paint; - paint.setStyle(SkPaint::kFill_Style); - paint.setFlags(SkPaint::kAntiAlias_Flag); - paint.setColor(kSignoutBackgroundColor); - canvas->GetSkCanvas()->drawPath(path, paint); - } -}; - } // namespace namespace chromeos { @@ -70,30 +53,30 @@ using login::kUserImageSize; class SignoutView : public views::View { public: explicit SignoutView(views::LinkListener* link_listener) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - const gfx::Font& font = rb.GetFont(ResourceBundle::SmallFont); + set_background( + views::Background::CreateSolidBackground(kSignoutBackgroundColor)); active_user_label_ = new views::Label( l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_ACTIVE_USER)); + const gfx::Font& font = + ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::SmallFont); active_user_label_->SetFont(font); - active_user_label_->SetColor(kTextColor); + active_user_label_->SetBackgroundColor(background()->get_color()); + active_user_label_->SetEnabledColor(kTextColor); signout_link_ = new views::Link( l10n_util::GetStringUTF16(IDS_SCREEN_LOCK_SIGN_OUT)); signout_link_->set_listener(link_listener); signout_link_->SetFont(font); - signout_link_->SetColor(kTextColor); signout_link_->set_focusable(true); - signout_link_->SetHighlightedColor(kTextColor); + signout_link_->SetBackgroundColor(background()->get_color()); + signout_link_->SetPressedColor(kTextColor); signout_link_->SetDisabledColor(kTextColor); - signout_link_->SetNormalColor(kTextColor); + signout_link_->SetEnabledColor(kTextColor); signout_link_->set_id(VIEW_ID_SCREEN_LOCKER_SIGNOUT_LINK); AddChildView(active_user_label_); AddChildView(signout_link_); - - set_background(views::Background::CreateBackgroundPainter( - true, new SignoutBackgroundPainter())); } // views::View overrides. @@ -174,15 +157,11 @@ class RemoveButton : public views::TextButton { const int kHorizontalPadding = 8; const int kCornerRadius = 4; - set_background( - CreateRoundedBackground( - kCornerRadius, kStrokeWidth, kButtonColor, kStrokeColor)); + set_background(CreateRoundedBackground(kCornerRadius, kStrokeWidth, + kButtonColor, kStrokeColor)); - set_border( - views::Border::CreateEmptyBorder(kVerticalPadding, - kHorizontalPadding, - kVerticalPadding, - kHorizontalPadding)); + set_border(views::Border::CreateEmptyBorder(kVerticalPadding, + kHorizontalPadding, kVerticalPadding, kHorizontalPadding)); UpdatePosition(); was_first_click_ = true; @@ -283,10 +262,9 @@ void UserView::Init(bool need_background) { AddChildView(signout_view_); } - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); remove_button_ = new RemoveButton( this, - *rb.GetBitmapNamed(IDR_CLOSE_BAR_H), + *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_CLOSE_BAR_H), UTF16ToWide(l10n_util::GetStringUTF16(IDS_LOGIN_REMOVE)), gfx::Point(kUserImageSize - kRemoveButtonPadding, kRemoveButtonPadding)); remove_button_->SetVisible(false); diff --git a/chrome/browser/chromeos/login/username_view.cc b/chrome/browser/chromeos/login/username_view.cc index 6000299..1e4df21 100644 --- a/chrome/browser/chromeos/login/username_view.cc +++ b/chrome/browser/chromeos/login/username_view.cc @@ -113,8 +113,9 @@ void UsernameView::PaintUsername(const gfx::Rect& bounds) { // Draw the text. // Note, direct call of the DrawStringInt method produces the green dots // along the text perimeter (when the label is place on the white background). + SkColor text_color = IsEnabled() ? enabled_color() : disabled_color(); SkColor kInvisibleHaloColor = 0x00000000; - canvas.DrawStringWithHalo(GetText(), font(), GetColor(), + canvas.DrawStringWithHalo(GetText(), font(), text_color, kInvisibleHaloColor, bounds.x() + margin_width_, bounds.y(), bounds.width() - 2 * margin_width_, bounds.height(), flags); diff --git a/chrome/browser/chromeos/options/vpn_config_view.cc b/chrome/browser/chromeos/options/vpn_config_view.cc index 1bedfe5..024dbb6 100644 --- a/chrome/browser/chromeos/options/vpn_config_view.cc +++ b/chrome/browser/chromeos/options/vpn_config_view.cc @@ -545,7 +545,7 @@ void VPNConfigView::Init(VirtualNetwork* vpn) { layout->SkipColumns(1); error_label_ = new views::Label(); error_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - error_label_->SetColor(SK_ColorRED); + error_label_->SetEnabledColor(SK_ColorRED); layout->AddView(error_label_); // Set or hide the UI, update comboboxes and error labels. diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc index 564a7ec..4c68acd 100644 --- a/chrome/browser/chromeos/options/wifi_config_view.cc +++ b/chrome/browser/chromeos/options/wifi_config_view.cc @@ -949,7 +949,7 @@ void WifiConfigView::Init(WifiNetwork* wifi, bool show_8021x) { layout->SkipColumns(1); error_label_ = new views::Label(); error_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - error_label_->SetColor(SK_ColorRED); + error_label_->SetEnabledColor(SK_ColorRED); layout->AddView(error_label_); // Initialize the field and checkbox values. diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc index aa86952..4ce2f5c 100644 --- a/chrome/browser/search_engines/template_url_fetcher.cc +++ b/chrome/browser/search_engines/template_url_fetcher.cc @@ -254,7 +254,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { case EXPLICIT_DEFAULT_PROVIDER: callbacks_->ConfirmSetDefaultSearchProvider(template_url_.release(), - model); + fetcher_->profile()); break; } diff --git a/chrome/browser/search_engines/template_url_fetcher_callbacks.h b/chrome/browser/search_engines/template_url_fetcher_callbacks.h index 34e0059..def6ce4 100644 --- a/chrome/browser/search_engines/template_url_fetcher_callbacks.h +++ b/chrome/browser/search_engines/template_url_fetcher_callbacks.h @@ -8,7 +8,6 @@ class Profile; class TemplateURL; -class TemplateURLService; // Callbacks for the TemplateURLFetcher. class TemplateURLFetcherCallbacks { @@ -18,15 +17,13 @@ class TemplateURLFetcherCallbacks { // Performs the confirmation step for setting the default search engine // described by |template_url|. Takes ownership of |template_url|. - virtual void ConfirmSetDefaultSearchProvider( - TemplateURL* template_url, - TemplateURLService* template_url_service) = 0; + virtual void ConfirmSetDefaultSearchProvider(TemplateURL* template_url, + Profile* profile) = 0; // Performs the confirmation step for adding a search engine described by // |template_url|. Takes ownership of |template_url|. - virtual void ConfirmAddSearchProvider( - TemplateURL* template_url, - Profile* profile) = 0; + virtual void ConfirmAddSearchProvider(TemplateURL* template_url, + Profile* profile) = 0; }; #endif // CHROME_BROWSER_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_CALLBACKS_H_ diff --git a/chrome/browser/search_engines/template_url_fetcher_unittest.cc b/chrome/browser/search_engines/template_url_fetcher_unittest.cc index d32d47c..11a2f50 100644 --- a/chrome/browser/search_engines/template_url_fetcher_unittest.cc +++ b/chrome/browser/search_engines/template_url_fetcher_unittest.cc @@ -29,12 +29,10 @@ class TemplateURLFetcherTestCallbacks : public TemplateURLFetcherCallbacks { virtual ~TemplateURLFetcherTestCallbacks(); // TemplateURLFetcherCallbacks implementation. - virtual void ConfirmSetDefaultSearchProvider( - TemplateURL* template_url, - TemplateURLService* template_url_service); - virtual void ConfirmAddSearchProvider( - TemplateURL* template_url, - Profile* profile); + virtual void ConfirmSetDefaultSearchProvider(TemplateURL* template_url, + Profile* profile) OVERRIDE; + virtual void ConfirmAddSearchProvider(TemplateURL* template_url, + Profile* profile) OVERRIDE; private: TemplateURLFetcherTest* test_; @@ -47,7 +45,7 @@ class TemplateURLFetcherTest : public testing::Test { public: TemplateURLFetcherTest(); - virtual void SetUp() { + virtual void SetUp() OVERRIDE { test_util_.SetUp(); test_util_.StartIOThread(); ASSERT_TRUE(test_util_.profile()); @@ -59,7 +57,7 @@ class TemplateURLFetcherTest : public testing::Test { ASSERT_TRUE(test_server_.Start()); } - virtual void TearDown() { + virtual void TearDown() OVERRIDE { test_util_.TearDown(); } @@ -68,12 +66,9 @@ class TemplateURLFetcherTest : public testing::Test { // TemplateURLFetcherCallbacks implementation. (Although not derived from // this class, these methods handle those calls for the test.) - virtual void ConfirmSetDefaultSearchProvider( - TemplateURL* template_url, - TemplateURLService* template_url_service); - virtual void ConfirmAddSearchProvider( - TemplateURL* template_url, - Profile* profile); + void ConfirmSetDefaultSearchProvider(TemplateURL* template_url, + Profile* profile); + void ConfirmAddSearchProvider(TemplateURL* template_url, Profile* profile); protected: // Schedules the download of the url. @@ -114,8 +109,8 @@ TemplateURLFetcherTestCallbacks::~TemplateURLFetcherTestCallbacks() { void TemplateURLFetcherTestCallbacks::ConfirmSetDefaultSearchProvider( TemplateURL* template_url, - TemplateURLService* template_url_service) { - test_->ConfirmSetDefaultSearchProvider(template_url, template_url_service); + Profile* profile) { + test_->ConfirmSetDefaultSearchProvider(template_url, profile); } void TemplateURLFetcherTestCallbacks::ConfirmAddSearchProvider( @@ -142,7 +137,7 @@ void TemplateURLFetcherTest::DestroyedCallback( void TemplateURLFetcherTest::ConfirmSetDefaultSearchProvider( TemplateURL* template_url, - TemplateURLService* template_url_service) { + Profile* profile) { last_callback_template_url_.reset(template_url); set_default_called_++; } diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 45ab2033..b21a519e 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -3913,12 +3913,11 @@ void Browser::OnInstallApplication(TabContentsWrapper* source, /////////////////////////////////////////////////////////////////////////////// // Browser, SearchEngineTabHelperDelegate implementation: -void Browser::ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) { +void Browser::ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) { window()->ConfirmSetDefaultSearchProvider(tab_contents, template_url, - template_url_service); + profile); } void Browser::ConfirmAddSearchProvider(const TemplateURL* template_url, diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index b5a9bb8..55946bb 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -994,10 +994,9 @@ class Browser : public TabHandlerDelegate, TabContentsWrapper* new_tab_contents) OVERRIDE; // Overridden from SearchEngineTabHelperDelegate: - virtual void ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) OVERRIDE; + virtual void ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) OVERRIDE; virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile) OVERRIDE; diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h index 63e213d..48844a9 100644 --- a/chrome/browser/ui/browser_window.h +++ b/chrome/browser/ui/browser_window.h @@ -194,10 +194,9 @@ class BrowserWindow { // Shows a confirmation dialog box for setting the default search engine // described by |template_url|. Takes ownership of |template_url|. - virtual void ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) { + virtual void ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) { // TODO(levin): Implement this for non-Windows platforms and make it pure. // http://crbug.com/38475 } diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc index 90d03a2..15eaf0d 100644 --- a/chrome/browser/ui/panels/panel.cc +++ b/chrome/browser/ui/panels/panel.cc @@ -321,10 +321,9 @@ void Panel::DisableInactiveFrame() { NOTIMPLEMENTED(); } -void Panel::ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) { +void Panel::ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) { NOTIMPLEMENTED(); } diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h index 3609dad..9496990 100644 --- a/chrome/browser/ui/panels/panel.h +++ b/chrome/browser/ui/panels/panel.h @@ -103,10 +103,9 @@ class Panel : public BrowserWindow, public NotificationObserver { virtual bool IsTabStripEditable() const OVERRIDE; virtual bool IsToolbarVisible() const OVERRIDE; virtual void DisableInactiveFrame() OVERRIDE; - virtual void ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) OVERRIDE; + virtual void ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) OVERRIDE; virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile) OVERRIDE; virtual void ToggleBookmarkBar() OVERRIDE; diff --git a/chrome/browser/ui/panels/panel_browser_frame_view.cc b/chrome/browser/ui/panels/panel_browser_frame_view.cc index a149c46..80d19c6 100644 --- a/chrome/browser/ui/panels/panel_browser_frame_view.cc +++ b/chrome/browser/ui/panels/panel_browser_frame_view.cc @@ -280,6 +280,7 @@ PanelBrowserFrameView::PanelBrowserFrameView(BrowserFrame* frame, title_label_ = new views::Label(string16()); title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + title_label_->SetAutoColorReadabilityEnabled(false); AddChildView(title_label_); mouse_watcher_.reset(new MouseWatcher(this)); @@ -587,7 +588,7 @@ void PanelBrowserFrameView::UpdateControlStyles(PaintState paint_state) { paint_state_ = paint_state; SkColor title_color = GetTitleColor(paint_state_); - title_label_->SetColor(title_color); + title_label_->SetEnabledColor(title_color); title_label_->SetFont(*GetTitleFont()); close_button_->SetBackground(title_color, diff --git a/chrome/browser/ui/panels/panel_browser_view.cc b/chrome/browser/ui/panels/panel_browser_view.cc index a9cb071..4e49ff4 100644 --- a/chrome/browser/ui/panels/panel_browser_view.cc +++ b/chrome/browser/ui/panels/panel_browser_view.cc @@ -495,6 +495,8 @@ NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { NativePanelTestingWin::NativePanelTestingWin( PanelBrowserView* panel_browser_view) : panel_browser_view_(panel_browser_view) { + PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); + frame_view->title_label_->SetAutoColorReadabilityEnabled(false); } void NativePanelTestingWin::PressLeftMouseButtonTitlebar( @@ -527,7 +529,7 @@ bool NativePanelTestingWin::VerifyDrawingAttention() const { PanelBrowserFrameView* frame_view = panel_browser_view_->GetFrameView(); SkColor attention_color = frame_view->GetTitleColor( PanelBrowserFrameView::PAINT_FOR_ATTENTION); - return attention_color == frame_view->title_label_->GetColor(); + return attention_color == frame_view->title_label_->enabled_color(); } bool NativePanelTestingWin::VerifyActiveState(bool is_active) { @@ -540,7 +542,7 @@ bool NativePanelTestingWin::VerifyActiveState(bool is_active) { return false; SkColor expected_color = frame_view->GetTitleColor(expected_paint_state); - return expected_color == frame_view->title_label_->GetColor(); + return expected_color == frame_view->title_label_->enabled_color(); } bool NativePanelTestingWin::IsWindowSizeKnown() const { diff --git a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc index 25a6231..9ca07cf 100644 --- a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc @@ -294,6 +294,7 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { Panel* panel = CreatePanel("PanelTest"); PanelBrowserView* browser_view = GetBrowserView(panel); PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); + frame_view->title_label_->SetAutoColorReadabilityEnabled(false); SkColor attention_color = frame_view->GetTitleColor( PanelBrowserFrameView::PAINT_FOR_ATTENTION); @@ -302,20 +303,20 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { browser_view->DrawAttention(); EXPECT_FALSE(browser_view->IsDrawingAttention()); MessageLoopForUI::current()->RunAllPending(); - EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); + EXPECT_NE(attention_color, frame_view->title_label_->enabled_color()); // Test that the attention is drawn when the expanded panel is not in focus. panel->Deactivate(); browser_view->DrawAttention(); EXPECT_TRUE(browser_view->IsDrawingAttention()); MessageLoopForUI::current()->RunAllPending(); - EXPECT_EQ(attention_color, frame_view->title_label_->GetColor()); + EXPECT_EQ(attention_color, frame_view->title_label_->enabled_color()); // Test that the attention is cleared. browser_view->StopDrawingAttention(); EXPECT_FALSE(browser_view->IsDrawingAttention()); MessageLoopForUI::current()->RunAllPending(); - EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); + EXPECT_NE(attention_color, frame_view->title_label_->enabled_color()); // Test that the attention is drawn and the title-bar is brought up when the // minimized panel is not in focus. @@ -326,7 +327,7 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { EXPECT_TRUE(browser_view->IsDrawingAttention()); EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); MessageLoopForUI::current()->RunAllPending(); - EXPECT_EQ(attention_color, frame_view->title_label_->GetColor()); + EXPECT_EQ(attention_color, frame_view->title_label_->enabled_color()); // Test that we cannot bring up other minimized panel if the mouse is over // the panel that draws attension. @@ -342,7 +343,7 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { EXPECT_FALSE(browser_view->IsDrawingAttention()); EXPECT_EQ(Panel::EXPANDED, panel->expansion_state()); MessageLoopForUI::current()->RunAllPending(); - EXPECT_NE(attention_color, frame_view->title_label_->GetColor()); + EXPECT_NE(attention_color, frame_view->title_label_->enabled_color()); panel->Close(); } diff --git a/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h b/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h index 1c5ddcf..fe7278b 100644 --- a/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h +++ b/chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h @@ -9,7 +9,6 @@ class Profile; class TabContents; class TemplateURL; -class TemplateURLService; // Objects implement this interface to get notified about changes in the // SearchEngineTabHelper and to provide necessary functionality. @@ -17,10 +16,9 @@ class SearchEngineTabHelperDelegate { public: // Shows a confirmation dialog box for setting the default search engine // described by |template_url|. Takes ownership of |template_url|. - virtual void ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) = 0; + virtual void ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) = 0; // Shows a confirmation dialog box for adding a search engine described by // |template_url|. Takes ownership of |template_url|. diff --git a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc index 37e6edc..2a1db23 100644 --- a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc +++ b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.cc @@ -28,15 +28,13 @@ TemplateURLFetcherUICallbacks::~TemplateURLFetcherUICallbacks() { void TemplateURLFetcherUICallbacks::ConfirmSetDefaultSearchProvider( TemplateURL* template_url, - TemplateURLService* template_url_service) { + Profile* profile) { scoped_ptr<TemplateURL> owned_template_url(template_url); if (!source_ || !source_->delegate() || !tab_contents_) return; - source_->delegate()->ConfirmSetDefaultSearchProvider( - tab_contents_, - owned_template_url.release(), - template_url_service); + source_->delegate()->ConfirmSetDefaultSearchProvider(tab_contents_, + owned_template_url.release(), profile); } void TemplateURLFetcherUICallbacks::ConfirmAddSearchProvider( diff --git a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h index 7c6a014..d0bf1bb 100644 --- a/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h +++ b/chrome/browser/ui/search_engines/template_url_fetcher_ui_callbacks.h @@ -7,6 +7,7 @@ #pragma once #include "base/basictypes.h" +#include "base/compiler_specific.h" #include "chrome/browser/search_engines/template_url_fetcher_callbacks.h" #include "content/common/notification_observer.h" #include "content/common/notification_registrar.h" @@ -23,17 +24,15 @@ class TemplateURLFetcherUICallbacks : public TemplateURLFetcherCallbacks, virtual ~TemplateURLFetcherUICallbacks(); // TemplateURLFetcherCallback implementation. - virtual void ConfirmSetDefaultSearchProvider( - TemplateURL* template_url, - TemplateURLService* template_url_service); - virtual void ConfirmAddSearchProvider( - TemplateURL* template_url, - Profile* profile); + virtual void ConfirmSetDefaultSearchProvider(TemplateURL* template_url, + Profile* profile) OVERRIDE; + virtual void ConfirmAddSearchProvider(TemplateURL* template_url, + Profile* profile) OVERRIDE; // NotificationObserver: virtual void Observe(int type, const NotificationSource& source, - const NotificationDetails& details); + const NotificationDetails& details) OVERRIDE; private: // The SearchEngineTabHelper where this request originated. Can be NULL if the diff --git a/chrome/browser/ui/views/about_chrome_view.cc b/chrome/browser/ui/views/about_chrome_view.cc index b8ddaac..292fe80 100644 --- a/chrome/browser/ui/views/about_chrome_view.cc +++ b/chrome/browser/ui/views/about_chrome_view.cc @@ -33,6 +33,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" +#include "ui/gfx/color_utils.h" #include "views/controls/button/text_button.h" #include "views/controls/link.h" #include "views/controls/textfield/textfield.h" @@ -59,10 +60,6 @@ const string16 kBeginLinkOss(ASCIIToUTF16("BEGIN_LINK_OSS")); const string16 kEndLinkChr(ASCIIToUTF16("END_LINK_CHR")); const string16 kEndLinkOss(ASCIIToUTF16("END_LINK_OSS")); -// The background bitmap used to draw the background color for the About box -// and the separator line (this is the image we will draw the logo on top of). -static const SkBitmap* kBackgroundBmp = NULL; - // Returns a substring from |text| between start and end. string16 StringSubRange(const string16& text, size_t start, size_t end) { DCHECK(end > start); @@ -109,11 +106,6 @@ AboutChromeView::AboutChromeView(Profile* profile) google_updater_ = new GoogleUpdate(); google_updater_->set_status_listener(this); #endif - - if (kBackgroundBmp == NULL) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - kBackgroundBmp = rb.GetBitmapNamed(IDR_ABOUT_BACKGROUND_COLOR); - } } AboutChromeView::~AboutChromeView() { @@ -166,7 +158,8 @@ void AboutChromeView::Init() { l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); about_title_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::BaseFont).DeriveFont(18)); - about_title_label_->SetColor(SK_ColorBLACK); + about_title_label_->SetBackgroundColor(SK_ColorWHITE); + about_title_label_->SetEnabledColor(SK_ColorBLACK); AddChildView(about_title_label_); // This is a text field so people can copy the version number from the dialog. @@ -223,6 +216,14 @@ void AboutChromeView::Init() { AddChildView(open_source_url_); open_source_url_->set_listener(this); +#if defined(OS_WIN) + SkColor background_color = color_utils::GetSysSkColor(COLOR_3DFACE); + copyright_label_->SetBackgroundColor(background_color); + main_text_label_->SetBackgroundColor(background_color); + chromium_url_->SetBackgroundColor(background_color); + open_source_url_->SetBackgroundColor(background_color); +#endif + // Add together all the strings in the dialog for the purpose of calculating // the height of the dialog. The space for the Terms of Service string is not // included (it is added later, if needed). @@ -381,8 +382,10 @@ void AboutChromeView::OnPaint(gfx::Canvas* canvas) { // Draw the background image color (and the separator) across the dialog. // This will become the background for the logo image at the top of the // dialog. - canvas->TileImageInt(*kBackgroundBmp, 0, 0, - dialog_dimensions_.width(), kBackgroundBmp->height()); + SkBitmap* background = ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_ABOUT_BACKGROUND_COLOR); + canvas->TileImageInt(*background, 0, 0, dialog_dimensions_.width(), + background->height()); gfx::Font font = ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont); diff --git a/chrome/browser/ui/views/avatar_menu_bubble_view.cc b/chrome/browser/ui/views/avatar_menu_bubble_view.cc index efe3399..441c82c 100644 --- a/chrome/browser/ui/views/avatar_menu_bubble_view.cc +++ b/chrome/browser/ui/views/avatar_menu_bubble_view.cc @@ -18,7 +18,6 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia.h" -#include "ui/gfx/color_utils.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image.h" #include "views/controls/button/image_button.h" @@ -32,8 +31,6 @@ const int kItemMarginY = 4; const int kIconWidth = 38; const int kIconMarginX = 6; const int kSeparatorPaddingY = 5; -const SkColor kHighlightBackgroundColor = SkColorSetRGB(0xe3, 0xed, 0xf6); -const SkColor kLinkColor = SkColorSetRGB(0, 0x79, 0xda); inline int Round(double x) { return static_cast<int>(x + 0.5); @@ -60,6 +57,9 @@ gfx::Rect GetCenteredAndScaledRect(int src_width, int src_height, return gfx::Rect(x, y, scaled_width, scaled_height); } + +// HighlightDelegate ---------------------------------------------------------- + // Delegate to callback when the highlight state of a control changes. class HighlightDelegate { public: @@ -67,29 +67,19 @@ class HighlightDelegate { virtual void OnHighlightStateChanged() = 0; }; + +// EditProfileLink ------------------------------------------------------------ + // A custom Link control that forwards highlight state changes. We need to do // this to make sure that the ProfileItemView looks highlighted even when // the mouse is over this link. class EditProfileLink : public views::Link { public: explicit EditProfileLink(const string16& title, - HighlightDelegate* delegate) - : views::Link(title), - delegate_(delegate), - state_(views::CustomButton::BS_NORMAL) { - } - - virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { - views::Link::OnMouseEntered(event); - state_ = views::CustomButton::BS_HOT; - delegate_->OnHighlightStateChanged(); - } + HighlightDelegate* delegate); - virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { - views::Link::OnMouseExited(event); - state_ = views::CustomButton::BS_NORMAL; - delegate_->OnHighlightStateChanged(); - } + virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; views::CustomButton::ButtonState state() { return state_; } @@ -98,163 +88,64 @@ class EditProfileLink : public views::Link { views::CustomButton::ButtonState state_; }; +EditProfileLink::EditProfileLink(const string16& title, + HighlightDelegate* delegate) + : views::Link(title), + delegate_(delegate), + state_(views::CustomButton::BS_NORMAL) { +} + +void EditProfileLink::OnMouseEntered(const views::MouseEvent& event) { + views::Link::OnMouseEntered(event); + state_ = views::CustomButton::BS_HOT; + delegate_->OnHighlightStateChanged(); +} + +void EditProfileLink::OnMouseExited(const views::MouseEvent& event) { + views::Link::OnMouseExited(event); + state_ = views::CustomButton::BS_NORMAL; + delegate_->OnHighlightStateChanged(); +} + + +// ProfileImageView ----------------------------------------------------------- + // A custom image view that ignores mouse events so that the parent can receive // them them instead. class ProfileImageView : public views::ImageView { public: - virtual bool HitTest(const gfx::Point& l) const OVERRIDE { - return false; - } + virtual bool HitTest(const gfx::Point& l) const OVERRIDE; }; +bool ProfileImageView::HitTest(const gfx::Point& l) const { + return false; +} + + +// ProfileItemView ------------------------------------------------------------ + // Control that shows information about a single profile. class ProfileItemView : public views::CustomButton, public HighlightDelegate { public: ProfileItemView(const AvatarMenuModel::Item& item, views::ButtonListener* switch_profile_listener, - views::LinkListener* edit_profile_listener) - : views::CustomButton(switch_profile_listener), - item_(item) { - image_view_ = new ProfileImageView(); - SkBitmap profile_icon = item_.icon; - if (item_.active) { - SkBitmap badged_icon = GetBadgedIcon(profile_icon); - image_view_->SetImage(&badged_icon); - } else { - image_view_->SetImage(&profile_icon); - } - AddChildView(image_view_); - - // Add a label to show the profile name. - name_label_ = new views::Label(item_.name); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); - int style = item_.active ? gfx::Font::BOLD : 0; - const int kNameFontDelta = 1; - name_label_->SetFont(base_font.DeriveFont(kNameFontDelta, style)); - name_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - AddChildView(name_label_); - - // Add a label to show the sync state. - sync_state_label_ = new views::Label(item_.sync_state); - const int kStateFontDelta = -1; - sync_state_label_->SetFont(base_font.DeriveFont(kStateFontDelta)); - sync_state_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - sync_state_label_->SetEnabled(false); - AddChildView(sync_state_label_); - - // Add an edit profile link. - edit_link_ = new EditProfileLink( - l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this); - edit_link_->set_listener(edit_profile_listener); - edit_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - edit_link_->MakeReadableOverBackgroundColor(kHighlightBackgroundColor); - edit_link_->SetNormalColor( - color_utils::GetReadableColor(kLinkColor, kHighlightBackgroundColor)); - edit_link_->SetHasFocusBorder(true); - AddChildView(edit_link_); - - OnHighlightStateChanged(); - } - - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - if (IsHighlighted()) { - canvas->FillRectInt(kHighlightBackgroundColor, 0, 0, - width(), height()); - } - } + views::LinkListener* edit_profile_listener); - virtual gfx::Size GetPreferredSize() OVERRIDE { - int width = std::max(name_label_->GetPreferredSize().width(), - sync_state_label_->GetPreferredSize().width()); - width = std::max(edit_link_->GetPreferredSize().width(), - width); - return gfx::Size(kIconWidth + kIconMarginX + width, kItemHeight); - } - - virtual void Layout() OVERRIDE { - // Profile icon. - const SkBitmap& icon = image_view_->GetImage(); - gfx::Rect icon_rect = GetCenteredAndScaledRect( - icon.width(), icon.height(), 0, 0, kIconWidth, height()); - image_view_->SetBoundsRect(icon_rect); - - int label_x = icon_rect.right() + kIconMarginX; - int max_label_width = width() - label_x; - gfx::Size name_size = name_label_->GetPreferredSize(); - name_size.set_width(std::min(name_size.width(), max_label_width)); - gfx::Size state_size = sync_state_label_->GetPreferredSize(); - state_size.set_width(std::min(state_size.width(), max_label_width)); - gfx::Size edit_size = edit_link_->GetPreferredSize(); - edit_size.set_width(std::min(edit_size.width(), max_label_width)); - - const int kNameStatePaddingY = 2; - int labels_height = name_size.height() + kNameStatePaddingY + - std::max(state_size.height(), edit_size.height()); - int y = (height() - labels_height) / 2; - name_label_->SetBounds(label_x, y, name_size.width(), name_size.height()); - - int bottom = y + labels_height; - sync_state_label_->SetBounds(label_x, bottom - state_size.height(), - state_size.width(), state_size.height()); - // The edit link overlaps the sync state label. - edit_link_->SetBounds(label_x, bottom - edit_size.height(), - edit_size.width(), edit_size.height()); - } + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void Layout() OVERRIDE; + virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; - virtual void OnHighlightStateChanged() OVERRIDE { - bool is_highlighted = IsHighlighted(); - bool show_edit = is_highlighted && item_.active; - sync_state_label_->SetVisible(!show_edit); - edit_link_->SetVisible(show_edit); - - SkColor background_color = - is_highlighted ? kHighlightBackgroundColor : Bubble::kBackgroundColor; - name_label_->MakeReadableOverBackgroundColor(background_color); - sync_state_label_->MakeReadableOverBackgroundColor(background_color); - - SchedulePaint(); - } - - virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { - views::CustomButton::OnMouseEntered(event); - OnHighlightStateChanged(); - } - - virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { - views::CustomButton::OnMouseExited(event); - OnHighlightStateChanged(); - } + virtual void OnHighlightStateChanged() OVERRIDE; EditProfileLink* edit_link() { return edit_link_; } const AvatarMenuModel::Item& item() { return item_; } private: - bool IsHighlighted() { - return state() == views::CustomButton::BS_PUSHED || - state() == views::CustomButton::BS_HOT || - edit_link_->state() == views::CustomButton::BS_PUSHED || - edit_link_->state() == views::CustomButton::BS_HOT; - } + static SkBitmap GetBadgedIcon(const SkBitmap& icon); - SkBitmap GetBadgedIcon(const SkBitmap& icon) { - gfx::Rect icon_rect = GetCenteredAndScaledRect( - icon.width(), icon.height(), 0, 0, kIconWidth, kItemHeight); - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SkBitmap badge = rb.GetImageNamed(IDR_PROFILE_SELECTED); - const float kBadgeOverlapRatioX = 1.0f / 5.0f; - int width = icon_rect.width() + badge.width() * kBadgeOverlapRatioX; - const float kBadgeOverlapRatioY = 1.0f / 3.0f; - int height = icon_rect.height() + badge.height() * kBadgeOverlapRatioY; - - gfx::CanvasSkia canvas(width, height, false); - canvas.DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(), 0, 0, - icon_rect.width(), icon_rect.height(), true); - canvas.DrawBitmapInt(badge, width - badge.width(), height - badge.height()); - return canvas.ExtractBitmap(); - } + bool IsHighlighted() const; EditProfileLink* edit_link_; views::ImageView* image_view_; @@ -263,8 +154,144 @@ class ProfileItemView : public views::CustomButton, views::Label* sync_state_label_; }; +ProfileItemView::ProfileItemView(const AvatarMenuModel::Item& item, + views::ButtonListener* switch_profile_listener, + views::LinkListener* edit_profile_listener) + : views::CustomButton(switch_profile_listener), + item_(item) { + image_view_ = new ProfileImageView(); + SkBitmap profile_icon = item_.icon; + if (item_.active) { + SkBitmap badged_icon(GetBadgedIcon(profile_icon)); + image_view_->SetImage(&badged_icon); + } else { + image_view_->SetImage(&profile_icon); + } + AddChildView(image_view_); + + // Add a label to show the profile name. + name_label_ = new views::Label(item_.name); + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + gfx::Font base_font = rb.GetFont(ResourceBundle::BaseFont); + int style = item_.active ? gfx::Font::BOLD : 0; + const int kNameFontDelta = 1; + name_label_->SetFont(base_font.DeriveFont(kNameFontDelta, style)); + name_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + AddChildView(name_label_); + + // Add a label to show the sync state. + sync_state_label_ = new views::Label(item_.sync_state); + const int kStateFontDelta = -1; + sync_state_label_->SetFont(base_font.DeriveFont(kStateFontDelta)); + sync_state_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + sync_state_label_->SetEnabled(false); + AddChildView(sync_state_label_); + + // Add an edit profile link. + edit_link_ = new EditProfileLink( + l10n_util::GetStringUTF16(IDS_PROFILES_EDIT_PROFILE_LINK), this); + edit_link_->set_listener(edit_profile_listener); + edit_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + edit_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); + edit_link_->SetHasFocusBorder(true); + AddChildView(edit_link_); + + OnHighlightStateChanged(); +} + +gfx::Size ProfileItemView::GetPreferredSize() { + int width = std::max(name_label_->GetPreferredSize().width(), + sync_state_label_->GetPreferredSize().width()); + width = std::max(edit_link_->GetPreferredSize().width(), width); + return gfx::Size(kIconWidth + kIconMarginX + width, kItemHeight); +} + +void ProfileItemView::Layout() { + // Profile icon. + const SkBitmap& icon = image_view_->GetImage(); + gfx::Rect icon_rect = GetCenteredAndScaledRect( + icon.width(), icon.height(), 0, 0, kIconWidth, height()); + image_view_->SetBoundsRect(icon_rect); + + int label_x = icon_rect.right() + kIconMarginX; + int max_label_width = width() - label_x; + gfx::Size name_size = name_label_->GetPreferredSize(); + name_size.set_width(std::min(name_size.width(), max_label_width)); + gfx::Size state_size = sync_state_label_->GetPreferredSize(); + state_size.set_width(std::min(state_size.width(), max_label_width)); + gfx::Size edit_size = edit_link_->GetPreferredSize(); + edit_size.set_width(std::min(edit_size.width(), max_label_width)); + + const int kNameStatePaddingY = 2; + int labels_height = name_size.height() + kNameStatePaddingY + + std::max(state_size.height(), edit_size.height()); + int y = (height() - labels_height) / 2; + name_label_->SetBounds(label_x, y, name_size.width(), name_size.height()); + + int bottom = y + labels_height; + sync_state_label_->SetBounds(label_x, bottom - state_size.height(), + state_size.width(), state_size.height()); + // The edit link overlaps the sync state label. + edit_link_->SetBounds(label_x, bottom - edit_size.height(), + edit_size.width(), edit_size.height()); +} + +void ProfileItemView::OnMouseEntered(const views::MouseEvent& event) { + views::CustomButton::OnMouseEntered(event); + OnHighlightStateChanged(); +} + +void ProfileItemView::OnMouseExited(const views::MouseEvent& event) { + views::CustomButton::OnMouseExited(event); + OnHighlightStateChanged(); +} + +void ProfileItemView::OnHighlightStateChanged() { + set_background(IsHighlighted() ? views::Background::CreateSolidBackground( + SkColorSetRGB(0xe3, 0xed, 0xf6)) : NULL); + SkColor background_color = background() ? + background()->get_color() : Bubble::kBackgroundColor; + name_label_->SetBackgroundColor(background_color); + sync_state_label_->SetBackgroundColor(background_color); + edit_link_->SetBackgroundColor(background_color); + + bool show_edit = IsHighlighted() && item_.active; + sync_state_label_->SetVisible(!show_edit); + edit_link_->SetVisible(show_edit); + SchedulePaint(); +} + +// static +SkBitmap ProfileItemView::GetBadgedIcon(const SkBitmap& icon) { + gfx::Rect icon_rect = GetCenteredAndScaledRect( + icon.width(), icon.height(), 0, 0, kIconWidth, kItemHeight); + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + SkBitmap badge = rb.GetImageNamed(IDR_PROFILE_SELECTED); + const float kBadgeOverlapRatioX = 1.0f / 5.0f; + int width = icon_rect.width() + badge.width() * kBadgeOverlapRatioX; + const float kBadgeOverlapRatioY = 1.0f / 3.0f; + int height = icon_rect.height() + badge.height() * kBadgeOverlapRatioY; + + gfx::CanvasSkia canvas(width, height, false); + canvas.DrawBitmapInt(icon, 0, 0, icon.width(), icon.height(), 0, 0, + icon_rect.width(), icon_rect.height(), true); + canvas.DrawBitmapInt(badge, width - badge.width(), height - badge.height()); + return canvas.ExtractBitmap(); +} + +bool ProfileItemView::IsHighlighted() const { + return state() == views::CustomButton::BS_PUSHED || + state() == views::CustomButton::BS_HOT || + edit_link_->state() == views::CustomButton::BS_PUSHED || + edit_link_->state() == views::CustomButton::BS_HOT; +} + } // namespace + +// AvatarMenuBubbleView ------------------------------------------------------- + AvatarMenuBubbleView::AvatarMenuBubbleView(Browser* browser) : add_profile_link_(NULL), browser_(browser) { @@ -385,9 +412,8 @@ void AvatarMenuBubbleView::OnAvatarMenuModelChanged( l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); add_profile_link_->set_listener(this); add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - add_profile_link_->MakeReadableOverBackgroundColor(Bubble::kBackgroundColor); - add_profile_link_->SetNormalColor( - color_utils::GetReadableColor(kLinkColor, Bubble::kBackgroundColor)); + add_profile_link_->SetBackgroundColor(Bubble::kBackgroundColor); + add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); AddChildView(add_profile_link_); PreferredSizeChanged(); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc index e279e8d..b4432d5 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc @@ -29,6 +29,7 @@ BookmarkBarInstructionsView::BookmarkBarInstructionsView(Delegate* delegate) updated_colors_(false) { instructions_ = new views::Label( l10n_util::GetStringUTF16(IDS_BOOKMARKS_NO_ITEMS)); + instructions_->SetAutoColorReadabilityEnabled(false); AddChildView(instructions_); if (browser_defaults::kShowImportOnBookmarkBar) { @@ -37,6 +38,7 @@ BookmarkBarInstructionsView::BookmarkBarInstructionsView(Delegate* delegate) // We don't want the link to alter tab navigation. import_link_->set_focusable(false); import_link_->set_listener(this); + import_link_->SetAutoColorReadabilityEnabled(false); AddChildView(import_link_); } } @@ -109,7 +111,7 @@ void BookmarkBarInstructionsView::UpdateColors() { updated_colors_ = true; SkColor text_color = theme_provider->GetColor(ThemeService::COLOR_BOOKMARK_TEXT); - instructions_->SetColor(text_color); + instructions_->SetEnabledColor(text_color); if (import_link_) - import_link_->SetColor(text_color); + import_link_->SetEnabledColor(text_color); } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc index 041d4c6..237b56b 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc @@ -24,7 +24,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" -#include "ui/gfx/color_utils.h" #include "views/controls/button/text_button.h" #include "views/controls/label.h" #include "views/controls/link.h" @@ -51,9 +50,6 @@ static const int kTitlePadding = 4; // of the field's left edge. static const int kMinimumFieldSize = 180; -// Bubble close image. -static SkBitmap* kCloseImage = NULL; - // Declared in browser_dialogs.h so callers don't have to depend on our header. namespace browser { @@ -179,20 +175,10 @@ BookmarkBubbleView::BookmarkBubbleView(BubbleDelegate* delegate, } void BookmarkBubbleView::Init() { - static SkColor kTitleColor; - static bool initialized = false; - if (!initialized) { - kTitleColor = color_utils::GetReadableColor(SkColorSetRGB(6, 45, 117), - Bubble::kBackgroundColor); - kCloseImage = ResourceBundle::GetSharedInstance().GetBitmapNamed( - IDR_INFO_BUBBLE_CLOSE); - - initialized = true; - } - remove_link_ = new views::Link(l10n_util::GetStringUTF16( IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); remove_link_->set_listener(this); + remove_link_->SetBackgroundColor(Bubble::kBackgroundColor); edit_button_ = new views::NativeTextButton( this, @@ -204,6 +190,7 @@ void BookmarkBubbleView::Init() { views::Label* combobox_label = new views::Label( l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); + combobox_label->SetBackgroundColor(Bubble::kBackgroundColor); parent_combobox_ = new views::Combobox(&parent_model_); parent_combobox_->SetSelectedItem(parent_model_.node_parent_index()); @@ -216,7 +203,8 @@ void BookmarkBubbleView::Init() { IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); title_label->SetFont( ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); - title_label->SetColor(kTitleColor); + title_label->SetBackgroundColor(Bubble::kBackgroundColor); + title_label->SetEnabledColor(SkColorSetRGB(6, 45, 117)); GridLayout* layout = new GridLayout(this); SetLayoutManager(layout); @@ -256,8 +244,10 @@ void BookmarkBubbleView::Init() { layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); layout->StartRow(0, 2); - layout->AddView(new views::Label( - l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT))); + views::Label* label = new views::Label( + l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); + label->SetBackgroundColor(Bubble::kBackgroundColor); + layout->AddView(label); title_tf_ = new views::Textfield(); title_tf_->SetText(GetTitle()); layout->AddView(title_tf_); @@ -342,7 +332,7 @@ bool BookmarkBubbleView::FadeInOnShow() { return false; } -string16 BookmarkBubbleView::accessible_name() { +string16 BookmarkBubbleView::GetAccessibleName() { return l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_ADD_BOOKMARK); } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h index 9eaad5f..7531b6e 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h @@ -93,7 +93,7 @@ class BookmarkBubbleView : public views::View, virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; virtual bool CloseOnEscape() OVERRIDE; virtual bool FadeInOnShow() OVERRIDE; - virtual string16 accessible_name() OVERRIDE; + virtual string16 GetAccessibleName() OVERRIDE; // Closes the bubble. void Close(); diff --git a/chrome/browser/ui/views/bubble/bubble.cc b/chrome/browser/ui/views/bubble/bubble.cc index 88b8b80..1ecfb3c 100644 --- a/chrome/browser/ui/views/bubble/bubble.cc +++ b/chrome/browser/ui/views/bubble/bubble.cc @@ -41,7 +41,7 @@ const SkColor Bubble::kBackgroundColor = SK_ColorWHITE; // BubbleDelegate --------------------------------------------------------- -string16 BubbleDelegate::accessible_name() { +string16 BubbleDelegate::GetAccessibleName() { return string16(); } @@ -229,7 +229,7 @@ void Bubble::InitBubble(views::Widget* parent, border_->SetOpacity(0); GetWidget()->SetOpacity(0); } - SetWindowText(GetNativeView(), delegate_->accessible_name().c_str()); + SetWindowText(GetNativeView(), delegate_->GetAccessibleName().c_str()); #elif defined(TOOLKIT_USES_GTK) views::Widget::InitParams params(type_); params.transparent = true; diff --git a/chrome/browser/ui/views/bubble/bubble.h b/chrome/browser/ui/views/bubble/bubble.h index 545038d..a7b6bf5 100644 --- a/chrome/browser/ui/views/bubble/bubble.h +++ b/chrome/browser/ui/views/bubble/bubble.h @@ -68,7 +68,7 @@ class BubbleDelegate { virtual bool FadeInOnShow() = 0; // The name of the window to which this delegate belongs. - virtual string16 accessible_name(); + virtual string16 GetAccessibleName(); }; // TODO(sky): this code is ifdef-tastic. It might be cleaner to refactor the diff --git a/chrome/browser/ui/views/default_search_view.cc b/chrome/browser/ui/views/default_search_view.cc index cd6fba0..568df1c 100644 --- a/chrome/browser/ui/views/default_search_view.cc +++ b/chrome/browser/ui/views/default_search_view.cc @@ -10,7 +10,9 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_prepopulate_data.h" +#include "chrome/browser/themes/theme_service.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/views/constrained_window_views.h" #include "content/browser/tab_contents/tab_contents.h" @@ -60,7 +62,8 @@ void GetShortNameAndLogoId(PrefService* prefs, views::Label* CreateProviderLabel(int message_id) { views::Label* choice_label = new views::Label(l10n_util::GetStringUTF16(message_id)); - choice_label->SetColor(SK_ColorBLACK); + choice_label->SetBackgroundColor(SK_ColorWHITE); + choice_label->SetEnabledColor(SK_ColorBLACK); choice_label->SetFont( choice_label->font().DeriveFont(1, gfx::Font::NORMAL)); return choice_label; @@ -89,7 +92,8 @@ views::View* CreateProviderLogo( } else { // No logo -- show a text label. views::Label* logo_label = new views::Label(short_name); - logo_label->SetColor(SK_ColorDKGRAY); + logo_label->SetBackgroundColor(SK_ColorWHITE); + logo_label->SetEnabledColor(SK_ColorDKGRAY); logo_label->SetFont(logo_label->font().DeriveFont(3, gfx::Font::BOLD)); logo_label->SetHorizontalAlignment(views::Label::ALIGN_CENTER); // Tooltip text provides accessibility for low-vision users. @@ -111,16 +115,18 @@ views::View* CreateProviderChoiceButton( // static void DefaultSearchView::Show(TabContents* tab_contents, - TemplateURL* default_url, - TemplateURLService* template_url_service) { - scoped_ptr<TemplateURL> template_url(default_url); - if (!template_url_service->CanMakeDefault(default_url) || - default_url->url()->GetHost().empty()) - return; - - // When the window closes, it will delete itself. - new DefaultSearchView(tab_contents, template_url.release(), - template_url_service); + TemplateURL* proposed_default_turl, + Profile* profile) { + TemplateURLService* template_url_service = + TemplateURLServiceFactory::GetForProfile(profile); + if (template_url_service->CanMakeDefault(proposed_default_turl) && + !proposed_default_turl->url()->GetHost().empty()) { + // When the window closes, it will delete itself. + new DefaultSearchView(tab_contents, proposed_default_turl, + template_url_service, profile->GetPrefs()); + } else { + delete proposed_default_turl; + } } DefaultSearchView::~DefaultSearchView() { @@ -128,8 +134,8 @@ DefaultSearchView::~DefaultSearchView() { void DefaultSearchView::OnPaint(gfx::Canvas* canvas) { // Fill in behind the background image with the standard gray toolbar color. - canvas->FillRectInt(SkColorSetRGB(237, 238, 237), 0, 0, width(), - background_image_->height()); + canvas->FillRectInt(GetThemeProvider()->GetColor(ThemeService::COLOR_TOOLBAR), + 0, 0, width(), background_image_->height()); // The rest of the dialog background should be white. DCHECK(height() > background_image_->height()); canvas->FillRectInt(SK_ColorWHITE, 0, background_image_->height(), width(), @@ -183,29 +189,21 @@ const views::Widget* DefaultSearchView::GetWidget() const { DefaultSearchView::DefaultSearchView(TabContents* tab_contents, TemplateURL* proposed_default_turl, - TemplateURLService* template_url_service) + TemplateURLService* template_url_service, + PrefService* prefs) : background_image_(NULL), default_provider_button_(NULL), proposed_provider_button_(NULL), proposed_turl_(proposed_default_turl), template_url_service_(template_url_service) { - Profile* profile = - Profile::FromBrowserContext(tab_contents->browser_context()); - PrefService* prefs = profile->GetPrefs(); SetupControls(prefs); // Show the dialog. - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); - new ConstrainedWindowViews(wrapper, this); + new ConstrainedWindowViews( + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents), this); } void DefaultSearchView::SetupControls(PrefService* prefs) { - using views::ColumnSet; - using views::GridLayout; - using views::ImageView; - using views::Label; - // Column set id's. const int kWholeDialogViewSetId = 0; const int kPaddedWholeDialogViewSetId = 1; @@ -231,61 +229,60 @@ void DefaultSearchView::SetupControls(PrefService* prefs) { &default_logo_id); // Now set-up the dialog contents. - GridLayout* layout = new views::GridLayout(this); + views::GridLayout* layout = new views::GridLayout(this); layout->SetInsets(0, 0, views::kPanelVertMargin, 0); SetLayoutManager(layout); // Add a column set that spans the whole dialog. - ColumnSet* whole_dialog_column_set = + views::ColumnSet* whole_dialog_column_set = layout->AddColumnSet(kWholeDialogViewSetId); - whole_dialog_column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, - 1, GridLayout::FIXED, - views::Widget::GetLocalizedContentsWidth( - IDS_DEFAULT_SEARCH_WIDTH_CHARS), - 0); + whole_dialog_column_set->AddColumn(views::GridLayout::LEADING, + views::GridLayout::LEADING, 1, views::GridLayout::FIXED, + views::Widget::GetLocalizedContentsWidth(IDS_DEFAULT_SEARCH_WIDTH_CHARS), + 0); // Add a column set that spans the whole dialog but obeying padding. - ColumnSet* padded_whole_dialog_column_set = + views::ColumnSet* padded_whole_dialog_column_set = layout->AddColumnSet(kPaddedWholeDialogViewSetId); padded_whole_dialog_column_set->AddPaddingColumn(1, views::kPanelVertMargin); - padded_whole_dialog_column_set->AddColumn( - GridLayout::LEADING, GridLayout::LEADING, - 1, GridLayout::USE_PREF, 0, 0); + padded_whole_dialog_column_set->AddColumn(views::GridLayout::LEADING, + views::GridLayout::LEADING, 1, views::GridLayout::USE_PREF, 0, 0); padded_whole_dialog_column_set->AddPaddingColumn(1, views::kPanelVertMargin); // Add a column set for the search engine choices. - ColumnSet* choices_column_set = layout->AddColumnSet(kChoicesViewSetId); + views::ColumnSet* choices_column_set = + layout->AddColumnSet(kChoicesViewSetId); choices_column_set->AddPaddingColumn(1, views::kPanelVertMargin); - choices_column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, - 1, GridLayout::USE_PREF, 0, 0); + choices_column_set->AddColumn(views::GridLayout::CENTER, + views::GridLayout::CENTER, 1, views::GridLayout::USE_PREF, 0, 0); choices_column_set->AddPaddingColumn( 1, views::kRelatedControlHorizontalSpacing); - choices_column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, - 1, GridLayout::USE_PREF, 0, 0); + choices_column_set->AddColumn(views::GridLayout::CENTER, + views::GridLayout::CENTER, 1, views::GridLayout::USE_PREF, 0, 0); choices_column_set->LinkColumnSizes(0, 2, -1); choices_column_set->AddPaddingColumn(1, views::kPanelVertMargin); // Add the "search box" image. layout->StartRow(0, kWholeDialogViewSetId); ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - background_image_ = new ImageView(); + background_image_ = new views::ImageView(); background_image_->SetImage(rb.GetBitmapNamed(IDR_SEARCH_ENGINE_DIALOG_TOP)); background_image_->EnableCanvasFlippingForRTLUI(true); - ImageView::Alignment horizontal_alignment = - base::i18n::IsRTL() ? ImageView::LEADING : ImageView::TRAILING; + views::ImageView::Alignment horizontal_alignment = base::i18n::IsRTL() ? + views::ImageView::LEADING : views::ImageView::TRAILING; background_image_->SetHorizontalAlignment(horizontal_alignment); layout->AddView(background_image_); // Add text informing the user about the requested default change. layout->StartRowWithPadding(0, kPaddedWholeDialogViewSetId, 1, views::kLabelToControlVerticalSpacing); - Label* summary_label = new Label(l10n_util::GetStringFUTF16( - IDS_DEFAULT_SEARCH_SUMMARY, - WideToUTF16(proposed_short_name))); - summary_label->SetColor(SK_ColorBLACK); + views::Label* summary_label = new views::Label(l10n_util::GetStringFUTF16( + IDS_DEFAULT_SEARCH_SUMMARY, WideToUTF16(proposed_short_name))); + summary_label->SetBackgroundColor(SK_ColorWHITE); + summary_label->SetEnabledColor(SK_ColorBLACK); summary_label->SetFont( summary_label->font().DeriveFont(1, gfx::Font::NORMAL)); - summary_label->SetHorizontalAlignment(Label::ALIGN_LEFT); + summary_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); layout->AddView(summary_label); // Add the labels for the tops of the choices. diff --git a/chrome/browser/ui/views/default_search_view.h b/chrome/browser/ui/views/default_search_view.h index d180724..983953e4 100644 --- a/chrome/browser/ui/views/default_search_view.h +++ b/chrome/browser/ui/views/default_search_view.h @@ -12,9 +12,11 @@ #include "views/window/dialog_delegate.h" class PrefService; +class Profile; class TabContents; class TemplateURL; class TemplateURLService; +class ThemeService; namespace gfx { class Canvas; @@ -29,15 +31,14 @@ class View; // Responsible for displaying the contents of the default search // prompt for when InstallSearchProvider(url, true) is called. -class DefaultSearchView - : public views::View, - public views::ButtonListener, - public views::DialogDelegate { +class DefaultSearchView : public views::View, + public views::ButtonListener, + public views::DialogDelegate { public: // Takes ownership of |proposed_default_turl|. static void Show(TabContents* tab_contents, - TemplateURL* , - TemplateURLService* template_url_service); + TemplateURL* proposed_default_turl, + Profile* profile); virtual ~DefaultSearchView(); @@ -64,7 +65,8 @@ class DefaultSearchView // Takes ownership of |proposed_default_turl|. DefaultSearchView(TabContents* tab_contents, TemplateURL* proposed_default_turl, - TemplateURLService* template_url_service); + TemplateURLService* template_url_service, + PrefService* prefs); // Initializes the labels and controls in the view. void SetupControls(PrefService* prefs); diff --git a/chrome/browser/ui/views/download/download_item_view.cc b/chrome/browser/ui/views/download/download_item_view.cc index 097f49c..59c3b0d 100644 --- a/chrome/browser/ui/views/download/download_item_view.cc +++ b/chrome/browser/ui/views/download/download_item_view.cc @@ -280,6 +280,7 @@ DownloadItemView::DownloadItemView(DownloadItem* download, dangerous_download_label_->SetMultiLine(true); dangerous_download_label_->SetHorizontalAlignment( views::Label::ALIGN_LEFT); + dangerous_download_label_->SetAutoColorReadabilityEnabled(false); AddChildView(dangerous_download_label_); SizeLabelToMinWidth(); } @@ -404,7 +405,7 @@ void DownloadItemView::OnDownloadOpened(DownloadItem* download) { // In dangerous mode we have to layout our buttons. void DownloadItemView::Layout() { if (IsDangerousMode()) { - dangerous_download_label_->SetColor( + dangerous_download_label_->SetEnabledColor( GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); int x = kLeftPadding + dangerous_mode_body_image_set_.top_left->width() + diff --git a/chrome/browser/ui/views/download/download_shelf_view.cc b/chrome/browser/ui/views/download/download_shelf_view.cc index c2c3338..a7ffc8a 100644 --- a/chrome/browser/ui/views/download/download_shelf_view.cc +++ b/chrome/browser/ui/views/download/download_shelf_view.cc @@ -93,44 +93,13 @@ DownloadShelfView::DownloadShelfView(Browser* browser, BrowserView* parent) mouse_watcher_.set_notify_on_exit_time_ms(kNotifyOnExitTimeMS); set_id(VIEW_ID_DOWNLOAD_SHELF); parent->AddChildView(this); - Init(); + Show(); } DownloadShelfView::~DownloadShelfView() { parent_->RemoveChildView(this); } -void DownloadShelfView::Init() { - ResourceBundle &rb = ResourceBundle::GetSharedInstance(); - arrow_image_ = new views::ImageView(); - arrow_image_->SetImage(rb.GetBitmapNamed(IDR_DOWNLOADS_FAVICON)); - AddChildView(arrow_image_); - - show_all_view_ = new views::Link( - l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); - show_all_view_->set_listener(this); - AddChildView(show_all_view_); - - close_button_ = new views::ImageButton(this); - close_button_->SetImage(views::CustomButton::BS_NORMAL, - rb.GetBitmapNamed(IDR_CLOSE_BAR)); - close_button_->SetImage(views::CustomButton::BS_HOT, - rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); - close_button_->SetImage(views::CustomButton::BS_PUSHED, - rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); - close_button_->SetAccessibleName( - l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); - UpdateButtonColors(); - AddChildView(close_button_); - - new_item_animation_.reset(new ui::SlideAnimation(this)); - new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); - - shelf_animation_.reset(new ui::SlideAnimation(this)); - shelf_animation_->SetSlideDuration(kShelfAnimationDurationMs); - Show(); -} - void DownloadShelfView::AddDownloadView(DownloadItemView* view) { mouse_watcher_.Stop(); @@ -180,10 +149,8 @@ void DownloadShelfView::RemoveDownloadView(View* view) { } views::View* DownloadShelfView::GetDefaultFocusableChild() { - if (!download_views_.empty()) - return download_views_[0]; - else - return show_all_view_; + return download_views_.empty() ? + static_cast<View*>(show_all_view_) : download_views_[0]; } void DownloadShelfView::OnPaint(gfx::Canvas* canvas) { @@ -251,12 +218,6 @@ void DownloadShelfView::AnimationEnded(const ui::Animation *animation) { } void DownloadShelfView::Layout() { - // Now that we know we have a parent, we can safely set our theme colors. - show_all_view_->SetColor( - GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); - set_background(views::Background::CreateSolidBackground( - GetThemeProvider()->GetColor(ThemeService::COLOR_TOOLBAR))); - // Let our base class layout our child views views::View::Layout(); @@ -327,6 +288,48 @@ void DownloadShelfView::Layout() { } } +void DownloadShelfView::ViewHierarchyChanged(bool is_add, + View* parent, + View* child) { + View::ViewHierarchyChanged(is_add, parent, child); + + if (is_add && (child == this)) { + set_background(views::Background::CreateSolidBackground( + GetThemeProvider()->GetColor(ThemeService::COLOR_TOOLBAR))); + + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + arrow_image_ = new views::ImageView(); + arrow_image_->SetImage(rb.GetBitmapNamed(IDR_DOWNLOADS_FAVICON)); + AddChildView(arrow_image_); + + show_all_view_ = new views::Link( + l10n_util::GetStringUTF16(IDS_SHOW_ALL_DOWNLOADS)); + show_all_view_->set_listener(this); + show_all_view_->SetBackgroundColor(background()->get_color()); + show_all_view_->SetEnabledColor( + GetThemeProvider()->GetColor(ThemeService::COLOR_BOOKMARK_TEXT)); + AddChildView(show_all_view_); + + close_button_ = new views::ImageButton(this); + close_button_->SetImage(views::CustomButton::BS_NORMAL, + rb.GetBitmapNamed(IDR_CLOSE_BAR)); + close_button_->SetImage(views::CustomButton::BS_HOT, + rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); + close_button_->SetImage(views::CustomButton::BS_PUSHED, + rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); + close_button_->SetAccessibleName( + l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); + UpdateButtonColors(); + AddChildView(close_button_); + + new_item_animation_.reset(new ui::SlideAnimation(this)); + new_item_animation_->SetSlideDuration(kNewItemAnimationDurationMs); + + shelf_animation_.reset(new ui::SlideAnimation(this)); + shelf_animation_->SetSlideDuration(kShelfAnimationDurationMs); + } +} + bool DownloadShelfView::CanFitFirstDownloadItem() { if (download_views_.empty()) return true; diff --git a/chrome/browser/ui/views/download/download_shelf_view.h b/chrome/browser/ui/views/download/download_shelf_view.h index 76994e8..8d5ae45 100644 --- a/chrome/browser/ui/views/download/download_shelf_view.h +++ b/chrome/browser/ui/views/download/download_shelf_view.h @@ -49,13 +49,16 @@ class DownloadShelfView : public AccessiblePaneView, void OpenedDownload(DownloadItemView* view); // Implementation of View. - virtual gfx::Size GetPreferredSize(); - virtual void Layout(); - virtual void OnPaint(gfx::Canvas* canvas); + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void Layout() OVERRIDE; + virtual void ViewHierarchyChanged(bool is_add, + View* parent, + View* child) OVERRIDE; + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; // Implementation of ui::AnimationDelegate. - virtual void AnimationProgressed(const ui::Animation* animation); - virtual void AnimationEnded(const ui::Animation* animation); + virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; + virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; // Implementation of views::LinkListener. // Invoked when the user clicks the 'show all downloads' link button. @@ -64,22 +67,23 @@ class DownloadShelfView : public AccessiblePaneView, // Implementation of ButtonListener. // Invoked when the user clicks the close button. Asks the browser to // hide the download shelf. - virtual void ButtonPressed(views::Button* button, const views::Event& event); + virtual void ButtonPressed(views::Button* button, + const views::Event& event) OVERRIDE; // Implementation of DownloadShelf. - virtual void AddDownload(BaseDownloadItemModel* download_model); - virtual bool IsShowing() const; - virtual bool IsClosing() const; - virtual void Show(); - virtual void Close(); - virtual Browser* browser() const; - - // Implementation of MouseWatcherDelegate. + virtual void AddDownload(BaseDownloadItemModel* download_model) OVERRIDE; + virtual bool IsShowing() const OVERRIDE; + virtual bool IsClosing() const OVERRIDE; + virtual void Show() OVERRIDE; + virtual void Close() OVERRIDE; + virtual Browser* browser() const OVERRIDE; + + // Implementation of MouseWatcherDelegate OVERRIDE. virtual void MouseMovedOutOfView(); // Override views::FocusChangeListener method from AccessiblePaneView. virtual void FocusWillChange(View* focused_before, - View* focused_now); + View* focused_now) OVERRIDE; // Removes a specified download view. The supplied view is deleted after // it's removed. @@ -87,18 +91,16 @@ class DownloadShelfView : public AccessiblePaneView, protected: // From AccessiblePaneView - virtual views::View* GetDefaultFocusableChild(); + virtual views::View* GetDefaultFocusableChild() OVERRIDE; private: - void Init(); - // Adds a View representing a download to this DownloadShelfView. // DownloadShelfView takes ownership of the View, and will delete it as // necessary. void AddDownloadView(DownloadItemView* view); // Paints the border. - virtual void OnPaintBorder(gfx::Canvas* canvas); + virtual void OnPaintBorder(gfx::Canvas* canvas) OVERRIDE; // Returns true if the shelf is wide enough to show the first download item. bool CanFitFirstDownloadItem(); diff --git a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc index a1270eb..7565390 100644 --- a/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc +++ b/chrome/browser/ui/views/extensions/extension_install_dialog_view.cc @@ -208,7 +208,8 @@ ExtensionInstallDialogView::ExtensionInstallDialogView( layout->StartRow(0, column_set_id); views::Label* user_count = new views::Label(prompt.GetUserCount()); - user_count->SetColor(SK_ColorGRAY); + user_count->SetAutoColorReadabilityEnabled(false); + user_count->SetEnabledColor(SK_ColorGRAY); user_count->SetFont(user_count->font().DeriveFont(kRatingFontSizeDelta)); layout->AddView(user_count); diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc index 9152f28..a3c04a6 100644 --- a/chrome/browser/ui/views/find_bar_view.cc +++ b/chrome/browser/ui/views/find_bar_view.cc @@ -89,7 +89,6 @@ FindBarView::FindBarView(FindBarHost* host) match_count_text_ = new views::Label(); match_count_text_->SetFont(rb.GetFont(ResourceBundle::BaseFont)); - match_count_text_->SetColor(kTextColorMatchCount); match_count_text_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); AddChildView(match_count_text_); @@ -183,22 +182,20 @@ void FindBarView::UpdateForResult(const FindNotificationDetails& result, find_text_->SelectAll(); } - if (!find_text.empty() && have_valid_range) { - match_count_text_->SetText( - l10n_util::GetStringFUTF16(IDS_FIND_IN_PAGE_COUNT, - base::IntToString16(result.active_match_ordinal()), - base::IntToString16(result.number_of_matches()))); - - UpdateMatchCountAppearance(result.number_of_matches() == 0 && - result.final_update()); - } else { + if (find_text.empty() || !have_valid_range) { // If there was no text entered, we don't show anything in the result count // area. - match_count_text_->SetText(string16()); - - UpdateMatchCountAppearance(false); + ClearMatchCount(); + return; } + match_count_text_->SetText(l10n_util::GetStringFUTF16(IDS_FIND_IN_PAGE_COUNT, + base::IntToString16(result.active_match_ordinal()), + base::IntToString16(result.number_of_matches()))); + + UpdateMatchCountAppearance(result.number_of_matches() == 0 && + result.final_update()); + // The match_count label may have increased/decreased in size so we need to // do a layout and repaint the dialog so that the find text field doesn't // partially overlap the match-count label when it increases on no matches. @@ -454,12 +451,14 @@ void FindBarView::UpdateMatchCountAppearance(bool no_match) { if (no_match) { match_count_text_->set_background( views::Background::CreateSolidBackground(kBackgroundColorNoMatch)); - match_count_text_->SetColor(kTextColorNoMatch); + match_count_text_->SetEnabledColor(kTextColorNoMatch); } else { match_count_text_->set_background( views::Background::CreateSolidBackground(kBackgroundColorMatch)); - match_count_text_->SetColor(kTextColorMatchCount); + match_count_text_->SetEnabledColor(kTextColorMatchCount); } + match_count_text_->SetBackgroundColor( + match_count_text_->background()->get_color()); } bool FindBarView::FocusForwarderView::OnMousePressed( diff --git a/chrome/browser/ui/views/first_run_bubble.cc b/chrome/browser/ui/views/first_run_bubble.cc index 9551cb2..a9edfaa 100644 --- a/chrome/browser/ui/views/first_run_bubble.cc +++ b/chrome/browser/ui/views/first_run_bubble.cc @@ -111,6 +111,7 @@ FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window, label1_ = new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_TITLE)); label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD)); + label1_->SetBackgroundColor(Bubble::kBackgroundColor); label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(label1_); @@ -119,6 +120,7 @@ FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window, label2_ = new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT)); label2_->SetMultiLine(true); label2_->SetFont(font); + label2_->SetBackgroundColor(Bubble::kBackgroundColor); label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); label2_->SizeToFit(ps.width() - kBubblePadding * 2); AddChildView(label2_); @@ -129,6 +131,7 @@ FirstRunBubbleView::FirstRunBubbleView(FirstRunBubble* bubble_window, label3_ = new views::Label(question_str); label3_->SetMultiLine(true); label3_->SetFont(font); + label3_->SetBackgroundColor(Bubble::kBackgroundColor); label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); label3_->SizeToFit(ps.width() - kBubblePadding * 2); AddChildView(label3_); @@ -275,13 +278,15 @@ FirstRunOEMBubbleView::FirstRunOEMBubbleView(FirstRunBubble* bubble_window, label1_ = new views::Label( l10n_util::GetStringUTF16(IDS_FR_OEM_BUBBLE_TITLE_1)); label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD)); - label1_->SetColor(SK_ColorRED); + label1_->SetBackgroundColor(Bubble::kBackgroundColor); + label1_->SetEnabledColor(SK_ColorRED); label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(label1_); label2_ = new views::Label( l10n_util::GetStringUTF16(IDS_FR_OEM_BUBBLE_TITLE_2)); label2_->SetFont(font.DeriveFont(3, gfx::Font::BOLD)); + label2_->SetBackgroundColor(Bubble::kBackgroundColor); label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(label2_); @@ -291,6 +296,7 @@ FirstRunOEMBubbleView::FirstRunOEMBubbleView(FirstRunBubble* bubble_window, l10n_util::GetStringUTF16(IDS_FR_OEM_BUBBLE_SUBTEXT)); label3_->SetMultiLine(true); label3_->SetFont(font); + label3_->SetBackgroundColor(Bubble::kBackgroundColor); label3_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); label3_->SizeToFit(ps.width() - kOEMBubblePadding * 2); AddChildView(label3_); @@ -423,6 +429,7 @@ FirstRunMinimalBubbleView::FirstRunMinimalBubbleView( IDS_FR_SE_BUBBLE_TITLE, GetDefaultSearchEngineName(profile_))); label1_->SetFont(font.DeriveFont(3, gfx::Font::BOLD)); + label1_->SetBackgroundColor(Bubble::kBackgroundColor); label1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(label1_); @@ -432,6 +439,7 @@ FirstRunMinimalBubbleView::FirstRunMinimalBubbleView( l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT)); label2_->SetMultiLine(true); label2_->SetFont(font); + label2_->SetBackgroundColor(Bubble::kBackgroundColor); label2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); label2_->SizeToFit(ps.width() - kBubblePadding * 2); AddChildView(label2_); diff --git a/chrome/browser/ui/views/first_run_search_engine_view.cc b/chrome/browser/ui/views/first_run_search_engine_view.cc index 1ab3f42..1e86752 100644 --- a/chrome/browser/ui/views/first_run_search_engine_view.cc +++ b/chrome/browser/ui/views/first_run_search_engine_view.cc @@ -19,6 +19,7 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/browser/themes/theme_service.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" #include "grit/google_chrome_strings.h" @@ -103,7 +104,8 @@ SearchEngineChoice::SearchEngineChoice(views::ButtonListener* listener, } else { // No logo -- we must show a text label. views::Label* logo_label = new views::Label(search_engine_->short_name()); - logo_label->SetColor(SK_ColorDKGRAY); + logo_label->SetBackgroundColor(SK_ColorWHITE); + logo_label->SetEnabledColor(SK_ColorDKGRAY); logo_label->SetFont(logo_label->font().DeriveFont(3, gfx::Font::BOLD)); logo_label->SetHorizontalAlignment(views::Label::ALIGN_CENTER); logo_label->SetTooltipText(WideToUTF16Hack(search_engine_->short_name())); @@ -140,30 +142,27 @@ void SearchEngineChoice::SetChoiceViewBounds(int x, int y, int width, choice_view_->SetBounds(x, y, width, height); } -FirstRunSearchEngineView::FirstRunSearchEngineView( - Profile* profile, bool randomize) +FirstRunSearchEngineView::FirstRunSearchEngineView(Profile* profile, + bool randomize) : background_image_(NULL), - profile_(profile), + template_url_service_(TemplateURLServiceFactory::GetForProfile(profile)), text_direction_is_rtl_(base::i18n::IsRTL()), + template_url_service_loaded_(false), + added_to_view_hierarchy_(false), randomize_(randomize) { // Don't show ourselves until all the search engines have loaded from // the profile -- otherwise we have nothing to show. SetVisible(false); // Start loading the search engines for the given profile. - search_engines_model_ = TemplateURLServiceFactory::GetForProfile(profile_); - if (search_engines_model_) { - DCHECK(!search_engines_model_->loaded()); - search_engines_model_->AddObserver(this); - search_engines_model_->Load(); - } else { - NOTREACHED(); - } - SetupControls(); + DCHECK(template_url_service_); + DCHECK(!template_url_service_->loaded()); + template_url_service_->AddObserver(this); + template_url_service_->Load(); } FirstRunSearchEngineView::~FirstRunSearchEngineView() { - search_engines_model_->RemoveObserver(this); + template_url_service_->RemoveObserver(this); } string16 FirstRunSearchEngineView::GetWindowTitle() const { @@ -173,21 +172,19 @@ string16 FirstRunSearchEngineView::GetWindowTitle() const { void FirstRunSearchEngineView::ButtonPressed(views::Button* sender, const views::Event& event) { SearchEngineChoice* choice = static_cast<SearchEngineChoice*>(sender); - TemplateURLService* template_url_service = - TemplateURLServiceFactory::GetForProfile(profile_); - DCHECK(template_url_service); - template_url_service->SetSearchEngineDialogSlot(choice->slot()); + DCHECK(template_url_service_); + template_url_service_->SetSearchEngineDialogSlot(choice->slot()); const TemplateURL* default_search = choice->GetSearchEngine(); if (default_search) - template_url_service->SetDefaultSearchProvider(default_search); + template_url_service_->SetDefaultSearchProvider(default_search); MessageLoop::current()->Quit(); } void FirstRunSearchEngineView::OnPaint(gfx::Canvas* canvas) { // Fill in behind the background image with the standard gray toolbar color. - canvas->FillRectInt(SkColorSetRGB(237, 238, 237), 0, 0, width(), - background_image_->height()); + canvas->FillRectInt(GetThemeProvider()->GetColor(ThemeService::COLOR_TOOLBAR), + 0, 0, width(), background_image_->height()); // The rest of the dialog background should be white. DCHECK(height() > background_image_->height()); canvas->FillRectInt(SK_ColorWHITE, 0, background_image_->height(), width(), @@ -195,108 +192,12 @@ void FirstRunSearchEngineView::OnPaint(gfx::Canvas* canvas) { } void FirstRunSearchEngineView::OnTemplateURLServiceChanged() { - using views::ImageView; - // We only watch the search engine model change once, on load. Remove // observer so we don't try to redraw if engines change under us. - search_engines_model_->RemoveObserver(this); - - // Add search engines in search_engines_model_ to buttons list. The - // first three will always be from prepopulated data. - std::vector<const TemplateURL*> template_urls = - search_engines_model_->GetTemplateURLs(); - - // If we have fewer than two search engines, end search engine dialog - // immediately, leaving imported default search engine setting intact. - if (template_urls.size() < 2) { - MessageLoop::current()->Quit(); - return; - } - - std::vector<const TemplateURL*>::iterator search_engine_iter; - - // Is user's default search engine included in first three prepopulated - // set? If not, we need to expand the dialog to include a fourth engine. - const TemplateURL* default_search_engine = - search_engines_model_->GetDefaultSearchProvider(); - // If the user's default choice is not in the first three search engines - // in template_urls, store it in |default_choice| and provide it as a - // fourth option. - SearchEngineChoice* default_choice = NULL; - - // First, see if we have 4 logos to show (in which case we use small logos). - // We show 4 logos when the default search engine the user has chosen is - // not one of the first three prepopulated engines. - if (template_urls.size() > 3) { - for (search_engine_iter = template_urls.begin() + 3; - search_engine_iter != template_urls.end(); - ++search_engine_iter) { - if (default_search_engine == *search_engine_iter) { - default_choice = new SearchEngineChoice(this, *search_engine_iter, - true); - } - } - } - - // Now that we know what size the logos should be, create new search engine - // choices for the view. If there are 2 search engines, only show 2 - // choices; for 3 or more, show 3 (unless the default is not one of the - // top 3, in which case show 4). - for (search_engine_iter = template_urls.begin(); - search_engine_iter < template_urls.begin() + - (template_urls.size() < 3 ? 2 : 3); - ++search_engine_iter) { - // Push first three engines into buttons: - SearchEngineChoice* choice = new SearchEngineChoice(this, - *search_engine_iter, default_choice != NULL); - search_engine_choices_.push_back(choice); - AddChildView(choice->GetView()); // The logo or text view. - AddChildView(choice); // The button associated with the choice. - } - // Push the default choice to the fourth position. - if (default_choice) { - search_engine_choices_.push_back(default_choice); - AddChildView(default_choice->GetView()); // The logo or text view. - AddChildView(default_choice); // The button associated with the choice. - } - - // Randomize order of logos if option has been set. - if (randomize_) { - std::random_shuffle(search_engine_choices_.begin(), - search_engine_choices_.end(), - base::RandGenerator); - // Assign to each choice the position in which it is shown on the screen. - std::vector<SearchEngineChoice*>::iterator it; - int slot = 0; - for (it = search_engine_choices_.begin(); - it != search_engine_choices_.end(); - it++) { - (*it)->set_slot(slot++); - } - } + template_url_service_->RemoveObserver(this); - // Now that we know how many logos to show, lay out and become visible. - SetVisible(true); - Layout(); - SchedulePaint(); - - // If the widget has detected that a screenreader is running, change the - // button names from "Choose" to the name of the search engine. This works - // around a bug that JAWS ignores the accessible name of a native button. - if (GetWidget() && GetWidget()->IsAccessibleWidget()) { - std::vector<SearchEngineChoice*>::iterator it; - for (it = search_engine_choices_.begin(); - it != search_engine_choices_.end(); - it++) { - (*it)->SetText((*it)->GetSearchEngine()->short_name()); - } - } - - // This will tell screenreaders that they should read the full text - // of this dialog to the user now (rather than waiting for the user - // to explore it). - GetWidget()->NotifyAccessibilityEvent( - this, ui::AccessibilityTypes::EVENT_ALERT, true); + template_url_service_loaded_ = true; + AddSearchEnginesIfPossible(); } gfx::Size FirstRunSearchEngineView::GetPreferredSize() { @@ -305,46 +206,6 @@ gfx::Size FirstRunSearchEngineView::GetPreferredSize() { IDS_FIRSTRUN_SEARCH_ENGINE_SELECTION_HEIGHT_LINES); } -void FirstRunSearchEngineView::SetupControls() { - using views::Background; - using views::ImageView; - using views::Label; - - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - background_image_ = new views::ImageView(); - background_image_->SetImage(rb.GetBitmapNamed(IDR_SEARCH_ENGINE_DIALOG_TOP)); - background_image_->EnableCanvasFlippingForRTLUI(true); - if (text_direction_is_rtl_) { - background_image_->SetHorizontalAlignment(ImageView::LEADING); - } else { - background_image_->SetHorizontalAlignment(ImageView::TRAILING); - } - - AddChildView(background_image_); - - int label_width = GetPreferredSize().width() - 2 * views::kPanelHorizMargin; - - // Add title and text asking the user to choose a search engine: - title_label_ = new Label(l10n_util::GetStringUTF16( - IDS_FR_SEARCH_MAIN_LABEL)); - title_label_->SetColor(SK_ColorBLACK); - title_label_->SetFont(title_label_->font().DeriveFont(3, gfx::Font::BOLD)); - title_label_->SetMultiLine(true); - title_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); - title_label_->SizeToFit(label_width); - AddChildView(title_label_); - - text_label_ = new Label(l10n_util::GetStringFUTF16( - IDS_FR_SEARCH_TEXT, - l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); - text_label_->SetColor(SK_ColorBLACK); - text_label_->SetFont(text_label_->font().DeriveFont(1, gfx::Font::NORMAL)); - text_label_->SetMultiLine(true); - text_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); - text_label_->SizeToFit(label_width); - AddChildView(text_label_); -} - void FirstRunSearchEngineView::Layout() { // Disable the close button. GetWidget()->EnableClose(false); @@ -457,7 +318,154 @@ void FirstRunSearchEngineView::Layout() { } // if (search_engine_choices.size() > 0) } +void FirstRunSearchEngineView::ViewHierarchyChanged(bool is_add, + View* parent, + View* child) { + View::ViewHierarchyChanged(is_add, parent, child); + + if (is_add && (child == this)) { + background_image_ = new views::ImageView(); + background_image_->SetImage( + ResourceBundle::GetSharedInstance().GetBitmapNamed( + IDR_SEARCH_ENGINE_DIALOG_TOP)); + background_image_->EnableCanvasFlippingForRTLUI(true); + background_image_->SetHorizontalAlignment(text_direction_is_rtl_ ? + views::ImageView::LEADING : views::ImageView::TRAILING); + + AddChildView(background_image_); + + int label_width = GetPreferredSize().width() - 2 * views::kPanelHorizMargin; + + // Add title and text asking the user to choose a search engine: + title_label_ = new views::Label(l10n_util::GetStringUTF16( + IDS_FR_SEARCH_MAIN_LABEL)); + title_label_->SetBackgroundColor( + GetThemeProvider()->GetColor(ThemeService::COLOR_TOOLBAR)); + title_label_->SetEnabledColor(SK_ColorBLACK); + title_label_->SetFont(title_label_->font().DeriveFont(3, gfx::Font::BOLD)); + title_label_->SetMultiLine(true); + title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + title_label_->SizeToFit(label_width); + AddChildView(title_label_); + + text_label_ = new views::Label(l10n_util::GetStringFUTF16( + IDS_FR_SEARCH_TEXT, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); + text_label_->SetBackgroundColor(SK_ColorWHITE); + text_label_->SetEnabledColor(SK_ColorBLACK); + text_label_->SetFont(text_label_->font().DeriveFont(1, gfx::Font::NORMAL)); + text_label_->SetMultiLine(true); + text_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); + text_label_->SizeToFit(label_width); + AddChildView(text_label_); + + added_to_view_hierarchy_ = true; + AddSearchEnginesIfPossible(); + } +} + void FirstRunSearchEngineView::GetAccessibleState( ui::AccessibleViewState* state) { state->role = ui::AccessibilityTypes::ROLE_ALERT; } + +void FirstRunSearchEngineView::AddSearchEnginesIfPossible() { + if (!template_url_service_loaded_ || !added_to_view_hierarchy_) + return; + + // Add search engines in template_url_service_ to buttons list. The + // first three will always be from prepopulated data. + std::vector<const TemplateURL*> template_urls = + template_url_service_->GetTemplateURLs(); + + // If we have fewer than two search engines, end search engine dialog + // immediately, leaving imported default search engine setting intact. + if (template_urls.size() < 2) { + MessageLoop::current()->Quit(); + return; + } + + std::vector<const TemplateURL*>::iterator search_engine_iter; + + // Is user's default search engine included in first three prepopulated + // set? If not, we need to expand the dialog to include a fourth engine. + const TemplateURL* default_search_engine = + template_url_service_->GetDefaultSearchProvider(); + // If the user's default choice is not in the first three search engines + // in template_urls, store it in |default_choice| and provide it as a + // fourth option. + SearchEngineChoice* default_choice = NULL; + + // First, see if we have 4 logos to show (in which case we use small logos). + // We show 4 logos when the default search engine the user has chosen is + // not one of the first three prepopulated engines. + if (template_urls.size() > 3) { + for (search_engine_iter = template_urls.begin() + 3; + search_engine_iter != template_urls.end(); + ++search_engine_iter) { + if (default_search_engine == *search_engine_iter) { + default_choice = new SearchEngineChoice(this, *search_engine_iter, + true); + } + } + } + + // Now that we know what size the logos should be, create new search engine + // choices for the view. If there are 2 search engines, only show 2 + // choices; for 3 or more, show 3 (unless the default is not one of the + // top 3, in which case show 4). + for (search_engine_iter = template_urls.begin(); + search_engine_iter < template_urls.begin() + + (template_urls.size() < 3 ? 2 : 3); + ++search_engine_iter) { + // Push first three engines into buttons: + SearchEngineChoice* choice = new SearchEngineChoice(this, + *search_engine_iter, default_choice != NULL); + search_engine_choices_.push_back(choice); + AddChildView(choice->GetView()); // The logo or text view. + AddChildView(choice); // The button associated with the choice. + } + // Push the default choice to the fourth position. + if (default_choice) { + search_engine_choices_.push_back(default_choice); + AddChildView(default_choice->GetView()); // The logo or text view. + AddChildView(default_choice); // The button associated with the choice. + } + + // Randomize order of logos if option has been set. + if (randomize_) { + std::random_shuffle(search_engine_choices_.begin(), + search_engine_choices_.end(), + base::RandGenerator); + // Assign to each choice the position in which it is shown on the screen. + std::vector<SearchEngineChoice*>::iterator it; + int slot = 0; + for (it = search_engine_choices_.begin(); + it != search_engine_choices_.end(); + it++) { + (*it)->set_slot(slot++); + } + } + + // Now that we know how many logos to show, lay out and become visible. + SetVisible(true); + Layout(); + SchedulePaint(); + + // If the widget has detected that a screenreader is running, change the + // button names from "Choose" to the name of the search engine. This works + // around a bug that JAWS ignores the accessible name of a native button. + if (GetWidget() && GetWidget()->IsAccessibleWidget()) { + std::vector<SearchEngineChoice*>::iterator it; + for (it = search_engine_choices_.begin(); + it != search_engine_choices_.end(); + it++) { + (*it)->SetText((*it)->GetSearchEngine()->short_name()); + } + } + + // This will tell screenreaders that they should read the full text + // of this dialog to the user now (rather than waiting for the user + // to explore it). + GetWidget()->NotifyAccessibilityEvent( + this, ui::AccessibilityTypes::EVENT_ALERT, true); +} diff --git a/chrome/browser/ui/views/first_run_search_engine_view.h b/chrome/browser/ui/views/first_run_search_engine_view.h index f160aed..2770167 100644 --- a/chrome/browser/ui/views/first_run_search_engine_view.h +++ b/chrome/browser/ui/views/first_run_search_engine_view.h @@ -17,6 +17,7 @@ class Profile; class TemplateURL; class TemplateURLService; +class ThemeService; namespace views { class ImageView; @@ -94,6 +95,9 @@ class FirstRunSearchEngineView : public views::WidgetDelegateView, // Overridden from views::View: virtual gfx::Size GetPreferredSize() OVERRIDE; virtual void Layout() OVERRIDE; + virtual void ViewHierarchyChanged(bool is_add, + View* parent, + View* child) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; // Override from views::View so we can draw the gray background at dialog top. @@ -105,11 +109,9 @@ class FirstRunSearchEngineView : public views::WidgetDelegateView, virtual void OnTemplateURLServiceChanged() OVERRIDE; private: - // Initializes the labels and controls in the view. - void SetupControls(); - - // Owned by the profile_. - TemplateURLService* search_engines_model_; + // Once the TemplateURLService has loaded and we're in a View hierarchy, it's + // OK to add the search engines from the TemplateURLService. + void AddSearchEnginesIfPossible(); // One for each search engine choice offered, either three or four. std::vector<SearchEngineChoice*> search_engine_choices_; @@ -117,11 +119,15 @@ class FirstRunSearchEngineView : public views::WidgetDelegateView, // If logos are to be displayed in random order. Used for UX testing. bool randomize_; - // The profile associated with this import process. - Profile* profile_; + // Services associated with the current profile. + TemplateURLService* template_url_service_; + ThemeService* theme_service_; bool text_direction_is_rtl_; + bool template_url_service_loaded_; + bool added_to_view_hierarchy_; + // Image of browser search box with grey background and bubble arrow. views::ImageView* background_image_; diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index e44302e..823bc9f 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -952,12 +952,11 @@ void BrowserView::DisableInactiveFrame() { #endif // No tricks are needed to get the right behavior on Linux. } -void BrowserView::ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) { +void BrowserView::ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) { #if defined(OS_WIN) && !defined(USE_AURA) - DefaultSearchView::Show(tab_contents, template_url, template_url_service); + DefaultSearchView::Show(tab_contents, template_url, profile); #else // TODO(levin): Implement for other platforms. Right now this is behind // a command line flag which is off. http://crbug.com/38475 diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 47af016..3c519ad 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -272,10 +272,9 @@ class BrowserView : public BrowserBubbleHost, virtual bool IsTabStripEditable() const OVERRIDE; virtual bool IsToolbarVisible() const OVERRIDE; virtual void DisableInactiveFrame() OVERRIDE; - virtual void ConfirmSetDefaultSearchProvider( - TabContents* tab_contents, - TemplateURL* template_url, - TemplateURLService* template_url_service) OVERRIDE; + virtual void ConfirmSetDefaultSearchProvider(TabContents* tab_contents, + TemplateURL* template_url, + Profile* profile) OVERRIDE; virtual void ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile) OVERRIDE; virtual void ToggleBookmarkBar() OVERRIDE; diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc index 239dbf4..c48a456 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc +++ b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc @@ -55,8 +55,9 @@ FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( link_.set_listener(bubble); link_.SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::LargeFont)); - link_.SetNormalColor(SK_ColorWHITE); - link_.SetHighlightedColor(SK_ColorWHITE); + link_.SetBackgroundColor(SK_ColorBLACK); + link_.SetEnabledColor(SK_ColorWHITE); + link_.SetPressedColor(SK_ColorWHITE); AddChildView(&link_); } diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc index 9f9c9ec..7115528 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.cc +++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc @@ -86,7 +86,7 @@ void ConfirmInfoBar::ViewHierarchyChanged(bool is_add, string16 link_text(delegate->GetLinkText()); if (!link_text.empty()) { - link_ = CreateLink(link_text, this, background()->get_color()); + link_ = CreateLink(link_text, this); AddChildView(link_); } } diff --git a/chrome/browser/ui/views/infobars/infobar_background.cc b/chrome/browser/ui/views/infobars/infobar_background.cc index 5822faa..151c519 100644 --- a/chrome/browser/ui/views/infobars/infobar_background.cc +++ b/chrome/browser/ui/views/infobars/infobar_background.cc @@ -8,6 +8,7 @@ #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia_paint.h" +#include "ui/gfx/color_utils.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "views/view.h" @@ -15,6 +16,8 @@ InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) : separator_color_(SK_ColorBLACK), top_color_(GetInfoBarTopColor(infobar_type)), bottom_color_(GetInfoBarBottomColor(infobar_type)) { + SetNativeControlColor( + color_utils::AlphaBlend(top_color_, bottom_color_, 128)); } InfoBarBackground::~InfoBarBackground() { diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index 5dcb4df..05369ce 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -76,26 +76,24 @@ InfoBarView::~InfoBarView() { DCHECK(!menu_runner_.get()); } -// static -views::Label* InfoBarView::CreateLabel(const string16& text) { +views::Label* InfoBarView::CreateLabel(const string16& text) const { views::Label* label = new views::Label(text, ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); - label->SetColor(SK_ColorBLACK); + label->SetBackgroundColor(background()->get_color()); + label->SetEnabledColor(SK_ColorBLACK); label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); return label; } -// static views::Link* InfoBarView::CreateLink(const string16& text, - views::LinkListener* listener, - const SkColor& background_color) { + views::LinkListener* listener) const { views::Link* link = new views::Link; link->SetText(text); link->SetFont( ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); link->SetHorizontalAlignment(views::Label::ALIGN_LEFT); link->set_listener(listener); - link->MakeReadableOverBackgroundColor(background_color); + link->SetBackgroundColor(background()->get_color()); return link; } diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h index f46232a..709ade6 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.h +++ b/chrome/browser/ui/views/infobars/infobar_view.h @@ -48,13 +48,12 @@ class InfoBarView : public InfoBar, virtual ~InfoBarView(); // Creates a label with the appropriate font and color for an infobar. - static views::Label* CreateLabel(const string16& text); + views::Label* CreateLabel(const string16& text) const; // Creates a link with the appropriate font and color for an infobar. // NOTE: Subclasses must ignore link clicks if we're unowned. - static views::Link* CreateLink(const string16& text, - views::LinkListener* listener, - const SkColor& background_color); + views::Link* CreateLink(const string16& text, + views::LinkListener* listener) const; // Creates a menu button with an infobar-specific appearance. // NOTE: Subclasses must ignore button presses if we're unowned. diff --git a/chrome/browser/ui/views/infobars/link_infobar.cc b/chrome/browser/ui/views/infobars/link_infobar.cc index be319d2..5558446 100644 --- a/chrome/browser/ui/views/infobars/link_infobar.cc +++ b/chrome/browser/ui/views/infobars/link_infobar.cc @@ -59,8 +59,7 @@ void LinkInfoBar::ViewHierarchyChanged(bool is_add, View* parent, View* child) { label_1_ = CreateLabel(message_text.substr(0, offset)); AddChildView(label_1_); - link_ = CreateLink(delegate->GetLinkText(), this, - background()->get_color()); + link_ = CreateLink(delegate->GetLinkText(), this); AddChildView(link_); label_2_ = CreateLabel(message_text.substr(offset)); diff --git a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc index d8e3e38..3333184 100644 --- a/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc +++ b/chrome/browser/ui/views/location_bar/icon_label_bubble_view.cc @@ -25,12 +25,14 @@ IconLabelBubbleView::IconLabelBubbleView(const int background_images[], : background_painter_(background_images), is_extension_icon_(false) { image_ = new views::ImageView(); - AddChildView(image_); image_->SetImage( ResourceBundle::GetSharedInstance().GetBitmapNamed(contained_image)); + AddChildView(image_); + label_ = new views::Label(); + label_->SetAutoColorReadabilityEnabled(false); + label_->SetEnabledColor(color); AddChildView(label_); - label_->SetColor(color); } IconLabelBubbleView::~IconLabelBubbleView() { diff --git a/chrome/browser/ui/views/location_bar/keyword_hint_view.cc b/chrome/browser/ui/views/location_bar/keyword_hint_view.cc index 699abe8..f9f764c 100644 --- a/chrome/browser/ui/views/location_bar/keyword_hint_view.cc +++ b/chrome/browser/ui/views/location_bar/keyword_hint_view.cc @@ -12,6 +12,7 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service.h" #include "chrome/browser/search_engines/template_url_service_factory.h" +#include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -27,10 +28,8 @@ static const int kTabImageYOffset = 4; static const SkBitmap* kTabButtonBitmap = NULL; KeywordHintView::KeywordHintView(Profile* profile) : profile_(profile) { - leading_label_ = new views::Label(); - trailing_label_ = new views::Label(); - AddChildView(leading_label_); - AddChildView(trailing_label_); + leading_label_ = CreateLabel(); + trailing_label_ = CreateLabel(); if (!kTabButtonBitmap) { kTabButtonBitmap = ResourceBundle::GetSharedInstance(). @@ -46,11 +45,6 @@ void KeywordHintView::SetFont(const gfx::Font& font) { trailing_label_->SetFont(font); } -void KeywordHintView::SetColor(const SkColor& color) { - leading_label_->SetColor(color); - trailing_label_->SetColor(color); -} - void KeywordHintView::SetKeyword(const string16& keyword) { keyword_ = keyword; if (keyword_.empty()) @@ -134,3 +128,13 @@ void KeywordHintView::Layout() { trailing_label_->SetBounds(x, 0, pref.width(), height()); } } + +views::Label* KeywordHintView::CreateLabel() { + views::Label* label = new views::Label(); + label->SetBackgroundColor(LocationBarView::GetColor(ToolbarModel::NONE, + LocationBarView::BACKGROUND)); + label->SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE, + LocationBarView::DEEMPHASIZED_TEXT)); + AddChildView(label); + return label; +} diff --git a/chrome/browser/ui/views/location_bar/keyword_hint_view.h b/chrome/browser/ui/views/location_bar/keyword_hint_view.h index 0658f43..0a928b5 100644 --- a/chrome/browser/ui/views/location_bar/keyword_hint_view.h +++ b/chrome/browser/ui/views/location_bar/keyword_hint_view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -34,8 +34,6 @@ class KeywordHintView : public views::View { void SetFont(const gfx::Font& font); - void SetColor(const SkColor& color); - void SetKeyword(const string16& keyword); string16 keyword() const { return keyword_; } @@ -46,6 +44,8 @@ class KeywordHintView : public views::View { virtual void Layout(); private: + views::Label* CreateLabel(); + views::Label* leading_label_; views::Label* trailing_label_; diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 5f8fdcb..32f0be5 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -217,13 +217,10 @@ void LocationBarView::Init() { selected_keyword_view_->SetFont(font_); selected_keyword_view_->SetVisible(false); - SkColor dimmed_text = GetColor(ToolbarModel::NONE, DEEMPHASIZED_TEXT); - keyword_hint_view_ = new KeywordHintView(profile); AddChildView(keyword_hint_view_); keyword_hint_view_->SetVisible(false); keyword_hint_view_->SetFont(font_); - keyword_hint_view_->SetColor(dimmed_text); for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { ContentSettingImageView* content_blocked_view = @@ -431,10 +428,6 @@ void LocationBarView::SetInstantSuggestion(const string16& text, if (!text.empty()) { if (!suggested_text_view_) { suggested_text_view_ = new SuggestedTextView(location_entry_->model()); - suggested_text_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - suggested_text_view_->SetColor( - GetColor(ToolbarModel::NONE, - LocationBarView::DEEMPHASIZED_TEXT)); suggested_text_view_->SetText(text); if (views::Widget::IsPureViews()) NOTIMPLEMENTED(); diff --git a/chrome/browser/ui/views/location_bar/suggested_text_view.cc b/chrome/browser/ui/views/location_bar/suggested_text_view.cc index e6956ed..a122a99 100644 --- a/chrome/browser/ui/views/location_bar/suggested_text_view.cc +++ b/chrome/browser/ui/views/location_bar/suggested_text_view.cc @@ -14,6 +14,10 @@ SuggestedTextView::SuggestedTextView(AutocompleteEditModel* edit_model) : edit_model_(edit_model), bg_color_(0) { + SetHorizontalAlignment(views::Label::ALIGN_LEFT); + SetAutoColorReadabilityEnabled(false); + SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE, + LocationBarView::DEEMPHASIZED_TEXT)); } SuggestedTextView::~SuggestedTextView() { @@ -32,8 +36,8 @@ void SuggestedTextView::StopAnimation() { // Reset the delegate so that we don't attempt to commit in AnimationEnded. animation_->set_delegate(NULL); animation_.reset(NULL); - SetColor(LocationBarView::GetColor(ToolbarModel::NONE, - LocationBarView::DEEMPHASIZED_TEXT)); + SetEnabledColor(LocationBarView::GetColor(ToolbarModel::NONE, + LocationBarView::DEEMPHASIZED_TEXT)); SchedulePaint(); } } @@ -57,8 +61,7 @@ void SuggestedTextView::AnimationProgressed(const ui::Animation* animation) { ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT); SkColor sel_fg_color = LocationBarView::GetColor( ToolbarModel::NONE, LocationBarView::SELECTED_TEXT); - SetColor(color_utils::AlphaBlend( - sel_fg_color, fg_color, + SetEnabledColor(color_utils::AlphaBlend(sel_fg_color, fg_color, ui::Tween::ValueBetween(animation->GetCurrentValue(), 0, 255))); SchedulePaint(); diff --git a/chrome/browser/ui/views/notifications/balloon_view.cc b/chrome/browser/ui/views/notifications/balloon_view.cc index ea74860..9813d46 100644 --- a/chrome/browser/ui/views/notifications/balloon_view.cc +++ b/chrome/browser/ui/views/notifications/balloon_view.cc @@ -366,7 +366,8 @@ void BalloonViewImpl::Show(Balloon* balloon) { options_menu_button_->SetBoundsRect(GetOptionsButtonBounds()); source_label_->SetFont(rb.GetFont(ResourceBundle::SmallFont)); - source_label_->SetColor(kControlBarTextColor); + source_label_->SetBackgroundColor(kControlBarBackgroundColor); + source_label_->SetEnabledColor(kControlBarTextColor); source_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); source_label_->SetBoundsRect(GetLabelBounds()); diff --git a/chrome/browser/ui/views/page_info_bubble_view.cc b/chrome/browser/ui/views/page_info_bubble_view.cc index 3a483e7..44d735a 100644 --- a/chrome/browser/ui/views/page_info_bubble_view.cc +++ b/chrome/browser/ui/views/page_info_bubble_view.cc @@ -308,7 +308,7 @@ bool PageInfoBubbleView::FadeInOnShow() { return false; } -string16 PageInfoBubbleView::accessible_name() { +string16 PageInfoBubbleView::GetAccessibleName() { return ASCIIToUTF16("PageInfoBubble"); } diff --git a/chrome/browser/ui/views/page_info_bubble_view.h b/chrome/browser/ui/views/page_info_bubble_view.h index b1b5c1a..023f927 100644 --- a/chrome/browser/ui/views/page_info_bubble_view.h +++ b/chrome/browser/ui/views/page_info_bubble_view.h @@ -47,7 +47,7 @@ class PageInfoBubbleView : public views::View, virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE; virtual bool CloseOnEscape() OVERRIDE; virtual bool FadeInOnShow() OVERRIDE; - virtual string16 accessible_name() OVERRIDE; + virtual string16 GetAccessibleName() OVERRIDE; // views::LinkListener methods: virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; diff --git a/chrome/browser/ui/views/sad_tab_view.cc b/chrome/browser/ui/views/sad_tab_view.cc index e5ae538..0322890 100644 --- a/chrome/browser/ui/views/sad_tab_view.cc +++ b/chrome/browser/ui/views/sad_tab_view.cc @@ -41,6 +41,8 @@ SadTabView::SadTabView(TabContents* tab_contents, Kind kind) : tab_contents_(tab_contents), kind_(kind), painted_(false), + base_font_(ResourceBundle::GetSharedInstance().GetFont( + ResourceBundle::BaseFont)), message_(NULL), help_link_(NULL), feedback_link_(NULL) { @@ -95,47 +97,33 @@ void SadTabView::ViewHierarchyChanged(bool is_add, columns->AddPaddingColumn(1, kPadding); views::ImageView* image = new views::ImageView(); - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - image->SetImage( - rb.GetBitmapNamed((kind_ == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB)); + image->SetImage(ResourceBundle::GetSharedInstance().GetBitmapNamed( + (kind_ == CRASHED) ? IDR_SAD_TAB : IDR_KILLED_TAB)); layout->StartRowWithPadding(0, column_set_id, 1, kPadding); layout->AddView(image); - views::Label* title = new views::Label(l10n_util::GetStringUTF16( + views::Label* title = CreateLabel(l10n_util::GetStringUTF16( (kind_ == CRASHED) ? IDS_SAD_TAB_TITLE : IDS_KILLED_TAB_TITLE)); - const gfx::Font& base_font = rb.GetFont(ResourceBundle::BaseFont); - title->SetFont(base_font.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); - title->SetColor(kTextColor); + title->SetFont(base_font_.DeriveFont(kTitleFontSizeDelta, gfx::Font::BOLD)); layout->StartRowWithPadding(0, column_set_id, 0, kPadding); layout->AddView(title); - message_ = new views::Label(l10n_util::GetStringUTF16( + message_ = CreateLabel(l10n_util::GetStringUTF16( (kind_ == CRASHED) ? IDS_SAD_TAB_MESSAGE : IDS_KILLED_TAB_MESSAGE)); - message_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); - message_->SetColor(kTextColor); message_->SetMultiLine(true); layout->StartRowWithPadding(0, column_set_id, 0, kPadding); layout->AddView(message_); if (tab_contents_) { - string16 help_link(l10n_util::GetStringUTF16( + help_link_ = CreateLink(l10n_util::GetStringUTF16( (kind_ == CRASHED) ? IDS_SAD_TAB_HELP_LINK : IDS_LEARN_MORE)); - help_link_ = new views::Link(help_link); - help_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); - help_link_->SetNormalColor(kTextColor); - help_link_->set_listener(this); if (kind_ == CRASHED) { size_t offset = 0; string16 help_text(l10n_util::GetStringFUTF16(IDS_SAD_TAB_HELP_MESSAGE, string16(), &offset)); - views::Label* help_prefix = - new views::Label(help_text.substr(0, offset)); - help_prefix->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); - help_prefix->SetColor(kTextColor); - views::Label* help_suffix = new views::Label(help_text.substr(offset)); - help_suffix->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); - help_suffix->SetColor(kTextColor); + views::Label* help_prefix = CreateLabel(help_text.substr(0, offset)); + views::Label* help_suffix = CreateLabel(help_text.substr(offset)); const int help_column_set_id = 1; views::ColumnSet* help_columns = layout->AddColumnSet(help_column_set_id); @@ -154,11 +142,8 @@ void SadTabView::ViewHierarchyChanged(bool is_add, layout->StartRowWithPadding(0, column_set_id, 0, kPadding); layout->AddView(help_link_); - feedback_link_ = new views::Link( + feedback_link_ = CreateLink( l10n_util::GetStringUTF16(IDS_KILLED_TAB_FEEDBACK_LINK)); - feedback_link_->SetFont(base_font.DeriveFont(kMessageFontSizeDelta)); - feedback_link_->SetNormalColor(kTextColor); - feedback_link_->set_listener(this); layout->StartRowWithPadding(0, column_set_id, 0, kPadding); layout->AddView(feedback_link_); } @@ -174,3 +159,20 @@ void SadTabView::OnPaint(gfx::Canvas* canvas) { } View::OnPaint(canvas); } + +views::Label* SadTabView::CreateLabel(const string16& text) { + views::Label* label = new views::Label(text); + label->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); + label->SetBackgroundColor(background()->get_color()); + label->SetEnabledColor(kTextColor); + return label; +} + +views::Link* SadTabView::CreateLink(const string16& text) { + views::Link* link = new views::Link(text); + link->SetFont(base_font_.DeriveFont(kMessageFontSizeDelta)); + link->SetBackgroundColor(background()->get_color()); + link->SetEnabledColor(kTextColor); + link->set_listener(this); + return link; +} diff --git a/chrome/browser/ui/views/sad_tab_view.h b/chrome/browser/ui/views/sad_tab_view.h index 11a0271..7fd5a28 100644 --- a/chrome/browser/ui/views/sad_tab_view.h +++ b/chrome/browser/ui/views/sad_tab_view.h @@ -57,9 +57,13 @@ class SadTabView : public views::View, virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; private: + views::Label* CreateLabel(const string16& text); + views::Link* CreateLink(const string16& text); + TabContents* tab_contents_; Kind kind_; bool painted_; + const gfx::Font& base_font_; views::Label* message_; views::Link* help_link_; views::Link* feedback_link_; diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index 55d8986..df5c398 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -400,7 +400,8 @@ class WrenchMenu::ZoomView : public WrenchMenuView, zoom_label_ = new Label( l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, 100)); - zoom_label_->SetColor(MenuConfig::instance().text_color); + zoom_label_->SetAutoColorReadabilityEnabled(false); + zoom_label_->SetEnabledColor(MenuConfig::instance().text_color); zoom_label_->SetHorizontalAlignment(Label::ALIGN_RIGHT); MenuButtonBackground* center_bg = new MenuButtonBackground(MenuButtonBackground::CENTER_BUTTON); diff --git a/views/controls/label.cc b/views/controls/label.cc index 2340ba6..33fbcd4 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -25,10 +25,6 @@ namespace views { -// The colors to use for enabled and disabled labels. -static SkColor kEnabledColor; -static SkColor kDisabledColor; - // static const char Label::kViewClassName[] = "views/Label"; @@ -81,17 +77,24 @@ const GURL Label::GetURL() const { return url_set_ ? url_ : GURL(UTF16ToUTF8(text_)); } -void Label::SetColor(const SkColor& color) { - color_ = color; +void Label::SetAutoColorReadabilityEnabled(bool enabled) { + auto_color_readability_ = enabled; + RecalculateColors(); +} + +void Label::SetEnabledColor(const SkColor& color) { + requested_enabled_color_ = color; + RecalculateColors(); } -SkColor Label::GetColor() const { - return color_; +void Label::SetDisabledColor(const SkColor& color) { + requested_disabled_color_ = color; + RecalculateColors(); } -void Label::MakeReadableOverBackgroundColor(const SkColor& background_color) { - SetColor(color_utils::GetReadableColor( - IsEnabled() ? kEnabledColor : kDisabledColor, background_color)); +void Label::SetBackgroundColor(const SkColor& color) { + background_color_ = color; + RecalculateColors(); } void Label::SetHorizontalAlignment(Alignment alignment) { @@ -216,11 +219,6 @@ int Label::GetHeightForWidth(int w) { return h + GetInsets().height(); } -void Label::OnEnabledChanged() { - View::OnEnabledChanged(); - SetColor(IsEnabled() ? kEnabledColor : kDisabledColor); -} - std::string Label::GetClassName() const { return kViewClassName; } @@ -269,9 +267,10 @@ void Label::PaintText(gfx::Canvas* canvas, const string16& text, const gfx::Rect& text_bounds, int flags) { - canvas->DrawStringInt(text, font_, color_, - text_bounds.x(), text_bounds.y(), - text_bounds.width(), text_bounds.height(), flags); + canvas->DrawStringInt(text, font_, + IsEnabled() ? actual_enabled_color_ : actual_disabled_color_, + text_bounds.x(), text_bounds.y(), text_bounds.width(), + text_bounds.height(), flags); if (HasFocus() || paint_as_focused_) { gfx::Rect focus_bounds = text_bounds; @@ -332,14 +331,19 @@ gfx::Font Label::GetDefaultFont() { void Label::Init(const string16& text, const gfx::Font& font) { static bool initialized = false; + static SkColor kDefaultEnabledColor; + static SkColor kDefaultDisabledColor; + static SkColor kDefaultBackgroundColor; if (!initialized) { #if defined(OS_WIN) - kEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); - kDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); + kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); + kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); + kDefaultBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); #else // TODO(beng): source from theme provider. - kEnabledColor = SK_ColorBLACK; - kDisabledColor = SK_ColorGRAY; + kDefaultEnabledColor = SK_ColorBLACK; + kDefaultDisabledColor = SK_ColorGRAY; + kDefaultBackgroundColor = SK_ColorWHITE; #endif initialized = true; @@ -348,9 +352,12 @@ void Label::Init(const string16& text, const gfx::Font& font) { contains_mouse_ = false; font_ = font; text_size_valid_ = false; - SetText(text); url_set_ = false; - color_ = kEnabledColor; + requested_enabled_color_ = kDefaultEnabledColor; + requested_disabled_color_ = kDefaultDisabledColor; + background_color_ = kDefaultBackgroundColor; + auto_color_readability_ = true; + RecalculateColors(); horiz_alignment_ = ALIGN_CENTER; is_multi_line_ = false; allow_character_break_ = false; @@ -359,6 +366,19 @@ void Label::Init(const string16& text, const gfx::Font& font) { rtl_alignment_mode_ = USE_UI_ALIGNMENT; paint_as_focused_ = false; has_focus_border_ = false; + + SetText(text); +} + +void Label::RecalculateColors() { + actual_enabled_color_ = auto_color_readability_ ? + color_utils::GetReadableColor(requested_enabled_color_, + background_color_) : + requested_enabled_color_; + actual_disabled_color_ = auto_color_readability_ ? + color_utils::GetReadableColor(requested_disabled_color_, + background_color_) : + requested_disabled_color_; } void Label::UpdateContainsMouse(const MouseEvent& event) { diff --git a/views/controls/label.h b/views/controls/label.h index 936a29d..1b7035c 100644 --- a/views/controls/label.h +++ b/views/controls/label.h @@ -75,16 +75,22 @@ class VIEWS_EXPORT Label : public View { // Return the label URL. const GURL GetURL() const; - // Set the color - virtual void SetColor(const SkColor& color); + // Enables or disables auto-color-readability (enabled by default). If this + // is enabled, then calls to set any foreground or background color will + // trigger an automatic mapper that uses color_utils::GetReadableColor() to + // ensure that the foreground colors are readable over the background color. + void SetAutoColorReadabilityEnabled(bool enabled); - // Return a reference to the currently used color. - virtual SkColor GetColor() const; + // Set the color. This will automatically force the color to be readable + // over the current background color. + virtual void SetEnabledColor(const SkColor& color); + void SetDisabledColor(const SkColor& color); - // If you'll be displaying the label over some non-system background color, - // call this with the relevant color and the label will auto-set its color to - // be readable. - virtual void MakeReadableOverBackgroundColor(const SkColor& background_color); + SkColor enabled_color() const { return actual_enabled_color_; } + + // Set the background color. This won't be explicitly drawn, but the label + // will force the text color to be readable over it. + void SetBackgroundColor(const SkColor& color); // Set horizontal alignment. If the locale is RTL, and the RTL alignment // setting is set as USE_UI_ALIGNMENT, the alignment is flipped around. @@ -168,8 +174,6 @@ class VIEWS_EXPORT Label : public View { // This method is used to layout multi-line labels. It is equivalent to // GetPreferredSize().height() if the receiver is not multi-line. virtual int GetHeightForWidth(int w); - // Sets the enabled state. Setting the enabled state resets the color. - virtual void OnEnabledChanged() OVERRIDE; virtual std::string GetClassName() const OVERRIDE; virtual bool HitTest(const gfx::Point& l) const OVERRIDE; // Mouse enter/exit are overridden to render mouse over background color. @@ -196,6 +200,8 @@ class VIEWS_EXPORT Label : public View { virtual gfx::Size GetTextSize() const; + SkColor disabled_color() const { return actual_disabled_color_; } + // Overridden from View: // Overridden to dirty our text bounds if we're multi-line. virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; @@ -216,6 +222,8 @@ class VIEWS_EXPORT Label : public View { void Init(const string16& text, const gfx::Font& font); + void RecalculateColors(); + // If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise // SetContainsMouse(false) is invoked. void UpdateContainsMouse(const MouseEvent& event); @@ -240,7 +248,12 @@ class VIEWS_EXPORT Label : public View { string16 text_; GURL url_; gfx::Font font_; - SkColor color_; + SkColor requested_enabled_color_; + SkColor actual_enabled_color_; + SkColor requested_disabled_color_; + SkColor actual_disabled_color_; + SkColor background_color_; + bool auto_color_readability_; mutable gfx::Size text_size_; mutable bool text_size_valid_; bool is_multi_line_; diff --git a/views/controls/label_unittest.cc b/views/controls/label_unittest.cc index 68fc296..9a86fc8 100644 --- a/views/controls/label_unittest.cc +++ b/views/controls/label_unittest.cc @@ -58,8 +58,9 @@ TEST(LabelTest, UrlProperty) { TEST(LabelTest, ColorProperty) { Label label; SkColor color = SkColorSetARGB(20, 40, 10, 5); - label.SetColor(color); - EXPECT_EQ(color, label.GetColor()); + label.SetAutoColorReadabilityEnabled(false); + label.SetEnabledColor(color); + EXPECT_EQ(color, label.enabled_color()); } TEST(LabelTest, AlignmentProperty) { diff --git a/views/controls/link.cc b/views/controls/link.cc index 2131ed1..08f2447 100644 --- a/views/controls/link.cc +++ b/views/controls/link.cc @@ -23,74 +23,23 @@ #include "ui/gfx/gtk_util.h" #endif -namespace { - -void GetColors(const SkColor* background_color, // NULL means "use default" - SkColor* highlighted_color, - SkColor* disabled_color, - SkColor* normal_color) { - static SkColor kHighlightedColor, kDisabledColor, kNormalColor; - static bool initialized = false; - if (!initialized) { -#if defined(OS_WIN) - kHighlightedColor = color_utils::GetReadableColor( - SkColorSetRGB(200, 0, 0), color_utils::GetSysSkColor(COLOR_WINDOW)); - kDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); - kNormalColor = color_utils::GetSysSkColor(COLOR_HOTLIGHT); -#else - // TODO(beng): source from theme provider. - kHighlightedColor = SK_ColorRED; - kDisabledColor = SK_ColorBLACK; - kNormalColor = SkColorSetRGB(0, 51, 153); -#endif - - initialized = true; - } - - if (background_color) { - *highlighted_color = color_utils::GetReadableColor(kHighlightedColor, - *background_color); - *disabled_color = color_utils::GetReadableColor(kDisabledColor, - *background_color); - *normal_color = color_utils::GetReadableColor(kNormalColor, - *background_color); - } else { - *highlighted_color = kHighlightedColor; - *disabled_color = kDisabledColor; - *normal_color = kNormalColor; - } -} -} - namespace views { const char Link::kViewClassName[] = "views/Link"; -Link::Link() : Label(string16()), - listener_(NULL), - highlighted_(false) { +Link::Link() : Label(string16()) { Init(); - set_focusable(true); } -Link::Link(const string16& title) : Label(title), - listener_(NULL), - highlighted_(false) { +Link::Link(const string16& title) : Label(title) { Init(); - set_focusable(true); -} - -void Link::Init() { - GetColors(NULL, &highlighted_color_, &disabled_color_, &normal_color_); - SetColor(normal_color_); - ValidateStyle(); } Link::~Link() { } void Link::OnEnabledChanged() { - ValidateStyle(); + RecalculateFont(); View::OnEnabledChanged(); } @@ -122,14 +71,14 @@ bool Link::OnMousePressed(const MouseEvent& event) { if (!IsEnabled() || (!event.IsLeftMouseButton() && !event.IsMiddleMouseButton())) return false; - SetHighlighted(true); + SetPressed(true); return true; } bool Link::OnMouseDragged(const MouseEvent& event) { - SetHighlighted(IsEnabled() && - (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && - HitTest(event.location())); + SetPressed(IsEnabled() && + (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) && + HitTest(event.location())); return true; } @@ -149,7 +98,7 @@ void Link::OnMouseReleased(const MouseEvent& event) { } void Link::OnMouseCaptureLost() { - SetHighlighted(false); + SetPressed(false); } bool Link::OnKeyPressed(const KeyEvent& event) { @@ -158,7 +107,7 @@ bool Link::OnKeyPressed(const KeyEvent& event) { if (!activate) return false; - SetHighlighted(false); + SetPressed(false); // Focus the link on key pressed. RequestFocus(); @@ -182,50 +131,66 @@ void Link::GetAccessibleState(ui::AccessibleViewState* state) { void Link::SetFont(const gfx::Font& font) { Label::SetFont(font); - ValidateStyle(); + RecalculateFont(); } -void Link::SetHighlightedColor(const SkColor& color) { - highlighted_color_ = color; - ValidateStyle(); +void Link::SetEnabledColor(const SkColor& color) { + requested_enabled_color_ = color; + if (!pressed_) + Label::SetEnabledColor(requested_enabled_color_); } -void Link::SetDisabledColor(const SkColor& color) { - disabled_color_ = color; - ValidateStyle(); +void Link::SetPressedColor(const SkColor& color) { + requested_pressed_color_ = color; + if (pressed_) + Label::SetEnabledColor(requested_pressed_color_); } -void Link::SetNormalColor(const SkColor& color) { - normal_color_ = color; - ValidateStyle(); -} +void Link::Init() { + static bool initialized = false; + static SkColor kDefaultEnabledColor; + static SkColor kDefaultDisabledColor; + static SkColor kDefaultPressedColor; + if (!initialized) { +#if defined(OS_WIN) + kDefaultEnabledColor = color_utils::GetSysSkColor(COLOR_HOTLIGHT); + kDefaultDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); + kDefaultPressedColor = SkColorSetRGB(200, 0, 0); +#else + // TODO(beng): source from theme provider. + kDefaultEnabledColor = SkColorSetRGB(0, 51, 153); + kDefaultDisabledColor = SK_ColorBLACK; + kDefaultPressedColor = SK_ColorRED; +#endif -void Link::MakeReadableOverBackgroundColor(const SkColor& color) { - GetColors(&color, &highlighted_color_, &disabled_color_, &normal_color_); - ValidateStyle(); + initialized = true; + } + + listener_ = NULL; + pressed_ = false; + SetEnabledColor(kDefaultEnabledColor); + SetDisabledColor(kDefaultDisabledColor); + SetPressedColor(kDefaultPressedColor); + RecalculateFont(); + set_focusable(true); } -void Link::SetHighlighted(bool f) { - if (f != highlighted_) { - highlighted_ = f; - ValidateStyle(); +void Link::SetPressed(bool pressed) { + if (pressed_ != pressed) { + pressed_ = pressed; + Label::SetEnabledColor(pressed_ ? + requested_pressed_color_ : requested_enabled_color_); + RecalculateFont(); SchedulePaint(); } } -void Link::ValidateStyle() { - if (IsEnabled()) { - if (!(font().GetStyle() & gfx::Font::UNDERLINED)) { - Label::SetFont( - font().DeriveFont(0, font().GetStyle() | gfx::Font::UNDERLINED)); - } - Label::SetColor(highlighted_ ? highlighted_color_ : normal_color_); - } else { - if (font().GetStyle() & gfx::Font::UNDERLINED) { - Label::SetFont( - font().DeriveFont(0, font().GetStyle() & ~gfx::Font::UNDERLINED)); - } - Label::SetColor(disabled_color_); +void Link::RecalculateFont() { + // The font should be underlined iff the link is enabled. + if (IsEnabled() == !(font().GetStyle() & gfx::Font::UNDERLINED)) { + Label::SetFont(font().DeriveFont(0, IsEnabled() ? + (font().GetStyle() | gfx::Font::UNDERLINED) : + (font().GetStyle() & ~gfx::Font::UNDERLINED))); } } diff --git a/views/controls/link.h b/views/controls/link.h index ac39f15..4a07f46 100644 --- a/views/controls/link.h +++ b/views/controls/link.h @@ -46,36 +46,29 @@ class VIEWS_EXPORT Link : public Label { // Overridden from Label: virtual void SetFont(const gfx::Font& font) OVERRIDE; - virtual void MakeReadableOverBackgroundColor(const SkColor& color) OVERRIDE; - void SetHighlightedColor(const SkColor& color); - void SetDisabledColor(const SkColor& color); - void SetNormalColor(const SkColor& color); + virtual void SetEnabledColor(const SkColor& color) OVERRIDE; + void SetPressedColor(const SkColor& color); static const char kViewClassName[]; private: - // A highlighted link is clicked. - void SetHighlighted(bool f); + void Init(); - // Make sure the label style matched the current state. - void ValidateStyle(); + void SetPressed(bool pressed); - void Init(); + void RecalculateFont(); LinkListener* listener_; - // Whether the link is currently highlighted. - bool highlighted_; - - // The color when the link is highlighted. - SkColor highlighted_color_; + // Whether the link is currently pressed. + bool pressed_; - // The color when the link is disabled. - SkColor disabled_color_; + // The color when the link is neither pressed nor disabled. + SkColor requested_enabled_color_; - // The color when the link is neither highlighted nor disabled. - SkColor normal_color_; + // The color when the link is pressed. + SkColor requested_pressed_color_; DISALLOW_COPY_AND_ASSIGN(Link); }; diff --git a/views/view_text_utils.cc b/views/view_text_utils.cc index d37498a..645f402 100644 --- a/views/view_text_utils.cc +++ b/views/view_text_utils.cc @@ -9,7 +9,6 @@ #include "base/logging.h" #include "base/utf_string_conversions.h" #include "ui/gfx/canvas_skia.h" -#include "ui/gfx/color_utils.h" #include "ui/gfx/size.h" #include "views/controls/label.h" #include "views/controls/link.h" @@ -88,13 +87,6 @@ void DrawTextStartingFrom(gfx::Canvas* canvas, const gfx::Font& font, bool text_direction_is_rtl, bool ltr_within_rtl) { -#if defined(OS_WIN) - const SkColor text_color = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); -#else - // TODO(beng): source from theme provider. - const SkColor text_color = SK_ColorBLACK; -#endif - // Iterate through line breaking opportunities (which in English would be // spaces and such). This tells us where to wrap. string16 text16(WideToUTF16(text)); @@ -140,8 +132,8 @@ void DrawTextStartingFrom(gfx::Canvas* canvas, int y = position->height() + bounds.y(); // Draw the text on the screen (mirrored, if RTL run). - canvas->DrawStringInt(word, font, text_color, x, y, w, font.GetHeight(), - flags); + canvas->DrawStringInt(word, font, label->enabled_color(), x, y, w, + font.GetHeight(), flags); if (!word.empty() && word[word.size() - 1] == '\x0a') { // When we come across '\n', we move to the beginning of the next line. |