summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 19:58:29 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 19:58:29 +0000
commiteab649b121dace28275e04d6d66e09cd0b7705dc (patch)
treedd1e01ed8eddd2a7231fe97c7a9dec4cd86482fe /chrome/browser/views
parent6fee4dfc66709548f053aeb6e1e4f10482e514da (diff)
downloadchromium_src-eab649b121dace28275e04d6d66e09cd0b7705dc.zip
chromium_src-eab649b121dace28275e04d6d66e09cd0b7705dc.tar.gz
chromium_src-eab649b121dace28275e04d6d66e09cd0b7705dc.tar.bz2
Use system themes where possible in Omnibox edit and dropdown; in other cases, provide a pair of colors and use whichever contrasts more with the relevant background color, to maintain readability.
BUG=92,18367 TEST=Use the omnibox on various non-default and high-contrast system themes. Observe that everything is always readable. Review URL: http://codereview.chromium.org/200009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc141
-rw-r--r--chrome/browser/views/location_bar_view.cc129
-rw-r--r--chrome/browser/views/location_bar_view.h16
3 files changed, 177 insertions, 109 deletions
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index e51993d..34e8831 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -28,55 +28,79 @@
#include "app/win_util.h"
#endif
-// Colors for various components of the view.
+namespace {
+
+enum ResultViewState {
+ NORMAL = 0,
+ SELECTED,
+ HOVERED,
+ NUM_STATES
+};
+
+enum ColorKind {
+ BACKGROUND = 0,
+ TEXT,
+ DIMMED_TEXT,
+ URL,
+ NUM_KINDS
+};
+
+SkColor GetColor(ResultViewState state, ColorKind kind) {
+ static bool initialized = false;
+ static SkColor colors[NUM_STATES][NUM_KINDS];
+ if (!initialized) {
#if defined(OS_WIN)
-static const SkColor kBackgroundColor =
- color_utils::GetSysSkColor(COLOR_WINDOW);
-static const SkColor kSelectedBackgroundColor =
- color_utils::GetSysSkColor(COLOR_HIGHLIGHT);
-static const SkColor kHoverBackgroundColor =
- SkColorSetA(kSelectedBackgroundColor, 127);
-static const SkColor kTextColor =
- color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
-static const SkColor kSelectedTextColor =
- color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
-static const SkColor kDimTextColor =
- color_utils::GetSysSkColor(COLOR_GRAYTEXT);
-static const SkColor kSelectedDimTextColor =
- color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
+ colors[NORMAL][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW);
+ colors[SELECTED][BACKGROUND] = color_utils::GetSysSkColor(COLOR_HIGHLIGHT);
+ colors[NORMAL][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
+ colors[SELECTED][TEXT] = color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
#else
-// TODO(beng): source from theme provider.
-static const SkColor kBackgroundColor = SK_ColorWHITE;
-static const SkColor kSelectedBackgroundColor = SK_ColorBLUE;
-static const SkColor kHoverBackgroundColor = SK_ColorCYAN;
-static const SkColor kTextColor = SK_ColorBLACK;
-static const SkColor kSelectedTextColor = SK_ColorWHITE;
-static const SkColor kDimTextColor = SK_ColorGRAY;
-static const SkColor kSelectedDimTextColor = SK_ColorWHITE;
+ // TODO(beng): source from theme provider.
+ colors[NORMAL][BACKGROUND] = SK_ColorWHITE;
+ colors[SELECTED][BACKGROUND] = SK_ColorBLUE;
+ colors[NORMAL][TEXT] = SK_ColorBLACK;
+ colors[SELECTED][TEXT] = SK_ColorWHITE;
#endif
-static const SkColor kStandardURLColor = SkColorSetRGB(0, 0x80, 0);
-static const SkColor kHighlightURLColor = SkColorSetRGB(0xD0, 0xFF, 0xD0);
-static const int kGlassPopupTransparency = 240;
-static const int kOpaquePopupTransparency = 255;
-static const int kHoverRowAlpha = 0x40;
+ colors[HOVERED][BACKGROUND] =
+ color_utils::AlphaBlend(colors[SELECTED][BACKGROUND],
+ colors[NORMAL][BACKGROUND], 64);
+ colors[HOVERED][TEXT] = colors[NORMAL][TEXT];
+ const SkColor kDarkURL = SkColorSetRGB(0, 128, 0);
+ const SkColor kLightURL = SkColorSetRGB(128, 255, 128);
+ for (int i = 0; i < NUM_STATES; ++i) {
+ colors[i][DIMMED_TEXT] =
+ color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128);
+ colors[i][URL] = color_utils::PickMoreReadableColor(kDarkURL, kLightURL,
+ colors[i][BACKGROUND]);
+ }
+ initialized = true;
+ }
+
+ return colors[state][kind];
+}
+
+const SkAlpha kGlassPopupAlpha = 240;
+const SkAlpha kOpaquePopupAlpha = 255;
// The minimum distance between the top and bottom of the icon and the top or
// bottom of the row. "Minimum" is used because the vertical padding may be
// larger, depending on the size of the text.
-static const int kIconVerticalPadding = 2;
+const int kIconVerticalPadding = 2;
// The minimum distance between the top and bottom of the text and the top or
// bottom of the row. See comment about the use of "minimum" for
// kIconVerticalPadding.
-static const int kTextVerticalPadding = 3;
+const int kTextVerticalPadding = 3;
// The padding at the left edge of the row, left of the icon.
-static const int kRowLeftPadding = 6;
+const int kRowLeftPadding = 6;
// The padding on the right edge of the row, right of the text.
-static const int kRowRightPadding = 3;
+const int kRowRightPadding = 3;
// The horizontal distance between the right edge of the icon and the left edge
// of the text.
-static const int kIconTextSpacing = 9;
+const int kIconTextSpacing = 9;
// The size delta between the font used for the edit and the result rows. Passed
// to gfx::Font::DeriveFont.
-static const int kEditFontAdjust = -1;
+const int kEditFontAdjust = -1;
+
+}
class AutocompleteResultView : public views::View {
public:
@@ -102,9 +126,7 @@ class AutocompleteResultView : public views::View {
virtual bool OnMouseDragged(const views::MouseEvent& event);
private:
- // Get colors for row backgrounds and text for different row states.
- SkColor GetBackgroundColor() const;
- SkColor GetTextColor() const;
+ ResultViewState GetState() const;
SkBitmap* GetIcon() const;
@@ -305,7 +327,9 @@ AutocompleteResultView::~AutocompleteResultView() {
}
void AutocompleteResultView::Paint(gfx::Canvas* canvas) {
- canvas->FillRectInt(GetBackgroundColor(), 0, 0, width(), height());
+ const ResultViewState state = GetState();
+ if (state != NORMAL)
+ canvas->drawColor(GetColor(state, BACKGROUND));
int x = MirroredLeftPointForRect(icon_bounds_);
@@ -394,16 +418,10 @@ bool AutocompleteResultView::OnMouseDragged(const views::MouseEvent& event) {
return false;
}
-SkColor AutocompleteResultView::GetBackgroundColor() const {
+ResultViewState AutocompleteResultView::GetState() const {
if (model_->IsSelectedIndex(model_index_))
- return kSelectedBackgroundColor;
- return model_->IsHoveredIndex(model_index_) ?
- kHoverBackgroundColor : kBackgroundColor;
-}
-
-SkColor AutocompleteResultView::GetTextColor() const {
- return model_->IsSelectedIndex(model_index_) ? kSelectedTextColor
- : kTextColor;
+ return SELECTED;
+ return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
}
SkBitmap* AutocompleteResultView::GetIcon() const {
@@ -529,16 +547,11 @@ gfx::Font AutocompleteResultView::GetFragmentFont(int style) const {
}
SkColor AutocompleteResultView::GetFragmentTextColor(int style) const {
- bool selected = model_->IsSelectedIndex(model_index_);
- if (style & ACMatchClassification::URL) {
- // TODO(beng): bring over the contrast logic from the old popup and massage
- // these values. See autocomplete_popup_view_win.cc and
- // LuminosityContrast etc.
- return selected ? kHighlightURLColor : kStandardURLColor;
- }
- if (style & ACMatchClassification::DIM)
- return selected ? kSelectedDimTextColor : kDimTextColor;
- return GetTextColor();
+ const ResultViewState state = GetState();
+ if (style & ACMatchClassification::URL)
+ return GetColor(state, URL);
+ return GetColor(state,
+ (style & ACMatchClassification::DIM) ? DIMMED_TEXT : TEXT);
}
void AutocompleteResultView::InitClass() {
@@ -838,7 +851,7 @@ void AutocompletePopupContentsView::PaintChildren(gfx::Canvas* canvas) {
// shader to fill a path representing the round-rect clipping region. This
// yields a nice anti-aliased edge.
gfx::Canvas contents_canvas(width(), height(), true);
- contents_canvas.FillRectInt(kBackgroundColor, 0, 0, width(), height());
+ contents_canvas.drawColor(GetColor(NORMAL, BACKGROUND));
View::PaintChildren(&contents_canvas);
// We want the contents background to be slightly transparent so we can see
// the blurry glass effect on DWM systems behind. We do this _after_ we paint
@@ -937,14 +950,10 @@ void AutocompletePopupContentsView::UpdateBlurRegion() {
void AutocompletePopupContentsView::MakeCanvasTransparent(
gfx::Canvas* canvas) {
// Allow the window blur effect to show through the popup background.
- SkPaint paint;
- SkColor transparency = GetThemeProvider()->ShouldUseNativeFrame() ?
- kGlassPopupTransparency : kOpaquePopupTransparency;
- paint.setColor(SkColorSetARGB(transparency, 255, 255, 255));
- paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
- paint.setStyle(SkPaint::kFill_Style);
- canvas->FillRectInt(0, 0, canvas->getDevice()->width(),
- canvas->getDevice()->height(), paint);
+ SkAlpha alpha = GetThemeProvider()->ShouldUseNativeFrame() ?
+ kGlassPopupAlpha : kOpaquePopupAlpha;
+ canvas->drawColor(SkColorSetA(GetColor(NORMAL, BACKGROUND), alpha),
+ SkXfermode::kDstIn_Mode);
}
// static
diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc
index 5dbcad8..a41b040 100644
--- a/chrome/browser/views/location_bar_view.cc
+++ b/chrome/browser/views/location_bar_view.cc
@@ -11,6 +11,7 @@
#include "build/build_config.h"
#include "app/gfx/canvas.h"
+#include "app/gfx/color_utils.h"
#include "app/gfx/favicon_size.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
@@ -47,28 +48,12 @@
#if defined(OS_WIN)
#include "app/win_util.h"
#include "chrome/browser/views/first_run_bubble.h"
-#else
-#include "base/gfx/gtk_util.h"
-#include "chrome/browser/gtk/location_bar_view_gtk.h"
#endif
using views::View;
-const int LocationBarView::kVertMargin = 2;
-
-const SkColor LocationBarView::kBackgroundColorByLevel[] = {
- SkColorSetRGB(255, 245, 195), // SecurityLevel SECURE: Yellow.
- SkColorSetRGB(255, 255, 255), // SecurityLevel NORMAL: White.
- SkColorSetRGB(255, 255, 255), // SecurityLevel INSECURE: White.
-};
-#if defined(OS_LINUX)
// static
-const GdkColor LocationBarViewGtk::kBackgroundColorByLevel[3] = {
- GDK_COLOR_RGB(255, 245, 195), // SecurityLevel SECURE: Yellow.
- GDK_COLOR_RGB(255, 255, 255), // SecurityLevel NORMAL: White.
- GDK_COLOR_RGB(255, 255, 255), // SecurityLevel INSECURE: White.
-};
-#endif
+const int LocationBarView::kVertMargin = 2;
// Padding on the right and left of the entry field.
static const int kEntryPadding = 3;
@@ -140,10 +125,6 @@ LocationBarView::~LocationBarView() {
DeletePageActionViews();
}
-bool LocationBarView::IsInitialized() const {
- return location_entry_view_ != NULL;
-}
-
void LocationBarView::Init() {
if (popup_window_mode_) {
font_ = ResourceBundle::GetSharedInstance().GetFont(
@@ -192,25 +173,18 @@ void LocationBarView::Init() {
selected_keyword_view_.SetVisible(false);
selected_keyword_view_.SetParentOwned(false);
-#if defined(OS_WIN)
- DWORD sys_color = GetSysColor(COLOR_GRAYTEXT);
- SkColor gray = SkColorSetRGB(GetRValue(sys_color), GetGValue(sys_color),
- GetBValue(sys_color));
-#else
- NOTIMPLEMENTED();
- SkColor gray = SK_ColorGRAY;
-#endif
+ SkColor dimmed_text = GetColor(false, DEEMPHASIZED_TEXT);
AddChildView(&type_to_search_view_);
type_to_search_view_.SetVisible(false);
type_to_search_view_.SetFont(font_);
- type_to_search_view_.SetColor(gray);
+ type_to_search_view_.SetColor(dimmed_text);
type_to_search_view_.SetParentOwned(false);
AddChildView(&keyword_hint_view_);
keyword_hint_view_.SetVisible(false);
keyword_hint_view_.SetFont(font_);
- keyword_hint_view_.SetColor(gray);
+ keyword_hint_view_.SetColor(dimmed_text);
keyword_hint_view_.SetParentOwned(false);
AddChildView(&security_image_view_);
@@ -232,6 +206,74 @@ void LocationBarView::Init() {
OnChanged();
}
+bool LocationBarView::IsInitialized() const {
+ return location_entry_view_ != NULL;
+}
+
+// static
+SkColor LocationBarView::GetColor(bool is_secure, ColorKind kind) {
+ enum SecurityState {
+ NOT_SECURE = 0,
+ SECURE,
+ NUM_STATES
+ };
+
+ static bool initialized = false;
+ static SkColor colors[NUM_STATES][NUM_KINDS];
+ if (!initialized) {
+#if defined(OS_WIN)
+ colors[NOT_SECURE][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW);
+ colors[NOT_SECURE][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
+ colors[NOT_SECURE][SELECTED_TEXT] =
+ color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
+#else
+ // TODO(beng): source from theme provider.
+ colors[NOT_SECURE][BACKGROUND] = SK_ColorWHITE;
+ colors[NOT_SECURE][TEXT] = SK_ColorBLACK;
+ colors[NOT_SECURE][SELECTED_TEXT] = SK_ColorWHITE;
+#endif
+ colors[SECURE][BACKGROUND] = SkColorSetRGB(255, 245, 195);
+ colors[SECURE][TEXT] = SkColorSetRGB(0, 0, 0);
+ colors[SECURE][SELECTED_TEXT] = 0; // Unused
+ colors[NOT_SECURE][DEEMPHASIZED_TEXT] =
+ color_utils::AlphaBlend(colors[NOT_SECURE][TEXT],
+ colors[NOT_SECURE][BACKGROUND], 128);
+ colors[SECURE][DEEMPHASIZED_TEXT] =
+ color_utils::AlphaBlend(colors[SECURE][TEXT],
+ colors[SECURE][BACKGROUND], 128);
+ const SkColor kDarkNotSecureText = SkColorSetRGB(200, 0, 0);
+ const SkColor kLightNotSecureText = SkColorSetRGB(255, 55, 55);
+ colors[NOT_SECURE][SECURITY_TEXT] =
+ color_utils::PickMoreReadableColor(kDarkNotSecureText,
+ kLightNotSecureText,
+ colors[NOT_SECURE][BACKGROUND]);
+ colors[SECURE][SECURITY_TEXT] = SkColorSetRGB(0, 150, 20);
+#if 0 // Info bubble background color is system theme window background color
+ colors[NOT_SECURE][SECURITY_INFO_BUBBLE_TEXT] =
+ colors[NOT_SECURE][SECURITY_TEXT];
+ const SkColor kDarkSecureInfoBubbleText = SkColorSetRGB(0, 153, 51);
+ const SkColor kLightSecureInfoBubbleText = SkColorSetRGB(102, 255, 152);
+ colors[SECURE][SECURITY_INFO_BUBBLE_TEXT] =
+ color_utils::PickMoreReadableColor(kDarkSecureInfoBubbleText,
+ kLightSecureInfoBubbleText,
+ colors[NOT_SECURE][BACKGROUND]);
+#else // Info bubble background color is white
+ colors[NOT_SECURE][SECURITY_INFO_BUBBLE_TEXT] = kDarkNotSecureText;
+ colors[SECURE][SECURITY_INFO_BUBBLE_TEXT] = SkColorSetRGB(0, 153, 51);
+#endif
+ const SkColor kDarkSchemeStrikeout = SkColorSetRGB(210, 0, 0);
+ const SkColor kLightSchemeStrikeout = SkColorSetRGB(255, 45, 45);
+ colors[NOT_SECURE][SCHEME_STRIKEOUT] =
+ color_utils::PickMoreReadableColor(kDarkSchemeStrikeout,
+ kLightSchemeStrikeout,
+ colors[NOT_SECURE][BACKGROUND]);
+ colors[SECURE][SCHEME_STRIKEOUT] = 0; // Unused
+ initialized = true;
+ }
+
+ return colors[is_secure ? SECURE : NOT_SECURE][kind];
+}
+
void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
SetSecurityIcon(model_->GetIcon());
RefreshPageActionViews();
@@ -282,8 +324,6 @@ void LocationBarView::Layout() {
void LocationBarView::Paint(gfx::Canvas* canvas) {
View::Paint(canvas);
- SkColor bg = kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()];
-
const SkBitmap* background =
popup_window_mode_ ?
kPopupBackground :
@@ -291,8 +331,10 @@ void LocationBarView::Paint(gfx::Canvas* canvas) {
canvas->TileImageInt(*background, 0, 0, 0, 0, width(), height());
int top_margin = TopMargin();
- canvas->FillRectInt(bg, 0, top_margin, width(),
- std::max(height() - top_margin - kVertMargin, 0));
+ canvas->FillRectInt(
+ GetColor(model_->GetSchemeSecurityLevel() == ToolbarModel::SECURE,
+ BACKGROUND),
+ 0, top_margin, width(), std::max(height() - top_margin - kVertMargin, 0));
}
void LocationBarView::VisibleBoundsInRootChanged() {
@@ -675,7 +717,7 @@ void LocationBarView::SetInfoText(const std::wstring& text,
info_label_.SetVisible(!text.empty());
info_label_.SetText(text);
if (text_type == ToolbarModel::INFO_EV_TEXT)
- info_label_.SetColor(SkColorSetRGB(0, 150, 20)); // Green.
+ info_label_.SetColor(GetColor(true, SECURITY_TEXT));
info_label_.SetTooltipText(tooltip_text);
}
@@ -1163,10 +1205,10 @@ bool LocationBarView::SecurityImageView::OnMousePressed(
void LocationBarView::SecurityImageView::ShowInfoBubble() {
std::wstring text;
- SkColor text_color;
- model_->GetIconHoverText(&text, &text_color);
-
- ShowInfoBubbleImpl(text, text_color);
+ model_->GetIconHoverText(&text);
+ ShowInfoBubbleImpl(text, GetColor(
+ model_->GetSecurityLevel() == ToolbarModel::SECURE,
+ SECURITY_INFO_BUBBLE_TEXT));
}
// PageActionImageView----------------------------------------------------------
@@ -1329,8 +1371,11 @@ bool LocationBarView::PageActionImageView::OnMousePressed(
}
void LocationBarView::PageActionImageView::ShowInfoBubble() {
- SkColor text_color = SK_ColorBLACK;
- ShowInfoBubbleImpl(ASCIIToWide(tooltip_), text_color);
+#if 0 // Info bubble background color is system theme window background color
+ ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT));
+#else // Info bubble background color is white
+ ShowInfoBubbleImpl(ASCIIToWide(tooltip_), SK_ColorBLACK);
+#endif
}
void LocationBarView::PageActionImageView::UpdateVisibility(
diff --git a/chrome/browser/views/location_bar_view.h b/chrome/browser/views/location_bar_view.h
index dcc00da..919821f 100644
--- a/chrome/browser/views/location_bar_view.h
+++ b/chrome/browser/views/location_bar_view.h
@@ -56,6 +56,17 @@ class LocationBarView : public LocationBar,
virtual void OnInputInProgress(bool in_progress) = 0;
};
+ enum ColorKind {
+ BACKGROUND = 0,
+ TEXT,
+ SELECTED_TEXT,
+ DEEMPHASIZED_TEXT,
+ SECURITY_TEXT,
+ SECURITY_INFO_BUBBLE_TEXT,
+ SCHEME_STRIKEOUT,
+ NUM_KINDS
+ };
+
LocationBarView(Profile* profile,
CommandUpdater* command_updater,
ToolbarModel* model,
@@ -70,6 +81,10 @@ class LocationBarView : public LocationBar,
// only be called when the receiving instance is attached to a view container.
bool IsInitialized() const;
+ // Returns the appropriate color for the desired kind, based on the user's
+ // system theme.
+ static SkColor GetColor(bool is_secure, ColorKind kind);
+
// Updates the location bar. We also reset the bar's permanent text and
// security style, and, if |tab_for_state_restoring| is non-NULL, also restore
// saved state that the tab holds.
@@ -140,7 +155,6 @@ class LocationBarView : public LocationBar,
virtual int PageActionVisibleCount();
static const int kVertMargin;
- static const SkColor kBackgroundColorByLevel[];
protected:
void Focus();