diff options
author | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-07 21:14:03 +0000 |
---|---|---|
committer | sail@chromium.org <sail@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-07 21:14:03 +0000 |
commit | c3217be503d6aeb920dc55f7c9a3f731ac63e3bd (patch) | |
tree | e5bbb3bad6e7abb6e14f98322f38c712ec4dbb1b | |
parent | cd2920af211d2ba926381c80b853a2e1d3eef3bc (diff) | |
download | chromium_src-c3217be503d6aeb920dc55f7c9a3f731ac63e3bd.zip chromium_src-c3217be503d6aeb920dc55f7c9a3f731ac63e3bd.tar.gz chromium_src-c3217be503d6aeb920dc55f7c9a3f731ac63e3bd.tar.bz2 |
Make infobar background gray
Currently page action infobars are blue on Windows and Linux and yellow on Mac. This change makes it gray on all platforms.
Screenshots:
http://www.dropmocks.com/mVNOW
Also see this CL:
http://codereview.chromium.org/7031069/
BUG=80432
TEST=Ran on Mac and Linux. Windows pending.
Review URL: http://codereview.chromium.org/7130001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88205 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/tab_contents/infobar.cc | 29 | ||||
-rw-r--r-- | chrome/browser/tab_contents/infobar.h | 16 | ||||
-rw-r--r-- | chrome/browser/themes/theme_service_mac.mm | 7 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/infobars/infobar_controller.mm | 3 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/infobars/infobar_gradient_view.mm | 35 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/translate/translate_infobar_base.mm | 18 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/infobars/infobar_gtk.cc | 36 | ||||
-rw-r--r-- | chrome/browser/ui/views/infobars/infobar_background.cc | 25 | ||||
-rw-r--r-- | chrome/browser/ui/views/infobars/infobar_background.h | 2 | ||||
-rw-r--r-- | skia/ext/skia_utils_mac.h | 5 | ||||
-rw-r--r-- | skia/ext/skia_utils_mac.mm | 8 |
12 files changed, 81 insertions, 108 deletions
diff --git a/chrome/browser/tab_contents/infobar.cc b/chrome/browser/tab_contents/infobar.cc index 540fffd..0a55bc5 100644 --- a/chrome/browser/tab_contents/infobar.cc +++ b/chrome/browser/tab_contents/infobar.cc @@ -2,17 +2,40 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#if defined(TOOLKIT_VIEWS) // TODO(pkasting): Port non-views to use this. - #include "chrome/browser/tab_contents/infobar.h" #include <cmath> #include "base/logging.h" #include "chrome/browser/tab_contents/infobar_container.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" #include "ui/base/animation/slide_animation.h" +SkColor GetInfoBarTopColor(InfoBarDelegate::Type infobar_type) { + // Yellow + static const SkColor kWarningBackgroundColorTop = + SkColorSetRGB(255, 242, 183); + // Gray + static const SkColor kPageActionBackgroundColorTop = + SkColorSetRGB(237, 237, 237); + + return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? + kWarningBackgroundColorTop : kPageActionBackgroundColorTop; +} + +SkColor GetInfoBarBottomColor(InfoBarDelegate::Type infobar_type) { + // Yellow + static const SkColor kWarningBackgroundColorBottom = + SkColorSetRGB(250, 230, 145); + // Gray + static const SkColor kPageActionBackgroundColorBottom = + SkColorSetRGB(217, 217, 217); + + return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? + kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; +} + +#if defined(TOOLKIT_VIEWS) // TODO(pkasting): Port non-views to use this. + InfoBar::InfoBar(TabContentsWrapper* owner, InfoBarDelegate* delegate) : owner_(owner), delegate_(delegate), diff --git a/chrome/browser/tab_contents/infobar.h b/chrome/browser/tab_contents/infobar.h index 874da69..53d270c9 100644 --- a/chrome/browser/tab_contents/infobar.h +++ b/chrome/browser/tab_contents/infobar.h @@ -2,19 +2,25 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#if defined(TOOLKIT_VIEWS) // TODO(pkasting): Port non-views to use this. - #ifndef CHROME_BROWSER_TAB_CONTENTS_INFOBAR_H_ #define CHROME_BROWSER_TAB_CONTENTS_INFOBAR_H_ #pragma once #include "base/basictypes.h" #include "base/scoped_ptr.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "third_party/skia/include/core/SkColor.h" #include "ui/base/animation/animation_delegate.h" #include "ui/gfx/size.h" +// TODO(sail): These functions should be static methods in the InfoBar class +// below once all platforms use that class. +SkColor GetInfoBarTopColor(InfoBarDelegate::Type infobar_type); +SkColor GetInfoBarBottomColor(InfoBarDelegate::Type infobar_type); + +#if defined(TOOLKIT_VIEWS) // TODO(pkasting): Port non-views to use this. + class InfoBarContainer; -class InfoBarDelegate; class TabContentsWrapper; namespace ui { @@ -116,10 +122,10 @@ class InfoBar : public ui::AnimationDelegate { DISALLOW_COPY_AND_ASSIGN(InfoBar); }; -#endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_H_ - #elif defined(TOOLKIT_USES_GTK) #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" #elif defined(OS_MACOSX) #include "chrome/browser/ui/cocoa/infobars/infobar.h" #endif + +#endif // CHROME_BROWSER_TAB_CONTENTS_INFOBAR_H_ diff --git a/chrome/browser/themes/theme_service_mac.mm b/chrome/browser/themes/theme_service_mac.mm index 683f171..69b07da 100644 --- a/chrome/browser/themes/theme_service_mac.mm +++ b/chrome/browser/themes/theme_service_mac.mm @@ -13,6 +13,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/image.h" +#include "skia/ext/skia_utils_mac.h" NSString* const kBrowserThemeDidChangeNotification = @"BrowserThemeDidChangeNotification"; @@ -132,11 +133,7 @@ NSColor* ThemeService::GetNSColor(int id, bool allow_default) const { if (is_default && !allow_default) return nil; - NSColor* color = [NSColor - colorWithCalibratedRed:SkColorGetR(sk_color)/255.0 - green:SkColorGetG(sk_color)/255.0 - blue:SkColorGetB(sk_color)/255.0 - alpha:SkColorGetA(sk_color)/255.0]; + NSColor* color = gfx::SkColorToCalibratedNSColor(sk_color); // We loaded successfully. Cache the color. if (color) diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm index d097658..5f6fbd6 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm @@ -14,6 +14,7 @@ #include "chrome/browser/ui/cocoa/infobars/infobar.h" #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" #import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" +#import "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" #include "ui/gfx/image.h" #include "webkit/glue/window_open_disposition.h" @@ -127,6 +128,8 @@ const float kAnimateCloseDuration = 0.12; [self initializeLabel]; [self addAdditionalControls]; + + [infoBarView_ setInfobarType:delegate_->GetInfoBarType()]; } // Called when someone clicks on the embedded link. diff --git a/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h b/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h index f5b4f9e..b0c6b6e 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h @@ -6,12 +6,17 @@ #define CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_GRADIENT_VIEW_H_ #pragma once +#include "chrome/browser/tab_contents/infobar_delegate.h" #import "chrome/browser/ui/cocoa/vertical_gradient_view.h" #import <Cocoa/Cocoa.h> // A custom view that draws the background gradient for an infobar. @interface InfoBarGradientView : VerticalGradientView + +// Sets the infobar type. This will change the view's gradient. +- (void)setInfobarType:(InfoBarDelegate::Type)infobarType; + @end #endif // CHROME_BROWSER_UI_COCOA_INFOBARS_INFOBAR_GRADIENT_VIEW_H_ diff --git a/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.mm b/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.mm index 8acd360..cb541b1 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_gradient_view.mm @@ -5,38 +5,21 @@ #include "chrome/browser/ui/cocoa/infobars/infobar_gradient_view.h" #include "base/memory/scoped_nsobject.h" +#include "chrome/browser/tab_contents/infobar.h" #import "chrome/browser/themes/theme_service.h" #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" #import "chrome/browser/ui/cocoa/themed_window.h" - -namespace { - -const double kBackgroundColorTop[3] = - {255.0 / 255.0, 242.0 / 255.0, 183.0 / 255.0}; -const double kBackgroundColorBottom[3] = - {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; -} +#include "skia/ext/skia_utils_mac.h" @implementation InfoBarGradientView -- (id)initWithFrame:(NSRect)frameRect { - if ((self = [super initWithFrame:frameRect])) { - NSColor* startingColor = - [NSColor colorWithCalibratedRed:kBackgroundColorTop[0] - green:kBackgroundColorTop[1] - blue:kBackgroundColorTop[2] - alpha:1.0]; - NSColor* endingColor = - [NSColor colorWithCalibratedRed:kBackgroundColorBottom[0] - green:kBackgroundColorBottom[1] - blue:kBackgroundColorBottom[2] - alpha:1.0]; - scoped_nsobject<NSGradient> gradient( - [[NSGradient alloc] initWithStartingColor:startingColor - endingColor:endingColor]); - [self setGradient:gradient]; - } - return self; +- (void)setInfobarType:(InfoBarDelegate::Type)infobarType { + SkColor topColor = GetInfoBarTopColor(infobarType); + SkColor bottomColor = GetInfoBarBottomColor(infobarType); + scoped_nsobject<NSGradient> gradient([[NSGradient alloc] + initWithStartingColor:gfx::SkColorToCalibratedNSColor(topColor) + endingColor:gfx::SkColorToCalibratedNSColor(bottomColor)]); + [self setGradient:gradient]; } - (NSColor*)strokeColor { diff --git a/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm b/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm index f4de135..7cefe71 100644 --- a/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm +++ b/chrome/browser/ui/cocoa/translate/translate_infobar_base.mm @@ -155,9 +155,6 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { // Reloads text for all labels for the current state. - (void)loadLabelText:(TranslateErrors::Type)error; -// Set the infobar background gradient. -- (void)setInfoBarGradientColor; - // Main function to update the toolbar graphic state and data model after // the state has changed. // Controls are moved around as needed and visibility changed to match the @@ -251,18 +248,6 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { [[self visibleControls] lastObject]]; } -- (void)setInfoBarGradientColor { - NSColor* startingColor = [NSColor colorWithCalibratedWhite:0.93 alpha:1.0]; - NSColor* endingColor = [NSColor colorWithCalibratedWhite:0.85 alpha:1.0]; - NSGradient* translateInfoBarGradient = - [[[NSGradient alloc] initWithStartingColor:startingColor - endingColor:endingColor] autorelease]; - - [infoBarView_ setGradient:translateInfoBarGradient]; - [infoBarView_ - setStrokeColor:[NSColor colorWithCalibratedWhite:0.75 alpha:1.0]]; -} - - (void)removeOkCancelButtons { // Removing okButton_ & cancelButton_ from the view may cause them // to be released and since we can still access them from other areas @@ -410,9 +395,6 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(TabContentsWrapper* owner) { NSRect cancelButtonFrame = [cancelButton_ frame]; spaceBetweenControls_ = NSMinX(cancelButtonFrame) - NSMaxX(okButtonFrame); - // Set infobar background color. - [self setInfoBarGradientColor]; - // Instantiate additional controls. [self constructViews]; diff --git a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc index d656649..e41e093 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc @@ -8,6 +8,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/platform_util.h" +#include "chrome/browser/tab_contents/infobar.h" #include "chrome/browser/ui/gtk/browser_window_gtk.h" #include "chrome/browser/ui/gtk/custom_button.h" #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" @@ -196,37 +197,18 @@ void InfoBar::AddLabelWithInlineLink(const string16& display_text, void InfoBar::GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double *b) { - // These constants are copied from corresponding skia constants from - // browser/ui/views/infobars/infobars.cc, and then changed into 0-1 ranged - // values for cairo. - switch (type) { - case InfoBarDelegate::WARNING_TYPE: - *r = 255.0 / 255.0; - *g = 242.0 / 255.0; - *b = 183.0 / 255.0; - break; - case InfoBarDelegate::PAGE_ACTION_TYPE: - *r = 218.0 / 255.0; - *g = 231.0 / 255.0; - *b = 249.0 / 255.0; - break; - } + SkColor color = GetInfoBarTopColor(type); + *r = SkColorGetR(color) / 255.0; + *g = SkColorGetG(color) / 255.0; + *b = SkColorGetB(color) / 255.0; } void InfoBar::GetBottomColor(InfoBarDelegate::Type type, double* r, double* g, double *b) { - switch (type) { - case InfoBarDelegate::WARNING_TYPE: - *r = 250.0 / 255.0; - *g = 230.0 / 255.0; - *b = 145.0 / 255.0; - break; - case InfoBarDelegate::PAGE_ACTION_TYPE: - *r = 179.0 / 255.0; - *g = 202.0 / 255.0; - *b = 231.0 / 255.0; - break; - } + SkColor color = GetInfoBarBottomColor(type); + *r = SkColorGetR(color) / 255.0; + *g = SkColorGetG(color) / 255.0; + *b = SkColorGetB(color) / 255.0; } void InfoBar::UpdateBorderColor() { diff --git a/chrome/browser/ui/views/infobars/infobar_background.cc b/chrome/browser/ui/views/infobars/infobar_background.cc index fa74322..b5d72c3 100644 --- a/chrome/browser/ui/views/infobars/infobar_background.cc +++ b/chrome/browser/ui/views/infobars/infobar_background.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/views/infobars/infobar_background.h" +#include "chrome/browser/tab_contents/infobar.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia_paint.h" @@ -12,33 +13,13 @@ InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) : separator_color_(SK_ColorBLACK), - top_color_(GetTopColor(infobar_type)), - bottom_color_(GetBottomColor(infobar_type)) { + top_color_(GetInfoBarTopColor(infobar_type)), + bottom_color_(GetInfoBarBottomColor(infobar_type)) { } InfoBarBackground::~InfoBarBackground() { } -SkColor InfoBarBackground::GetTopColor(InfoBarDelegate::Type infobar_type) { - static const SkColor kWarningBackgroundColorTop = - SkColorSetRGB(255, 242, 183); - static const SkColor kPageActionBackgroundColorTop = - SkColorSetRGB(218, 231, 249); - - return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? - kWarningBackgroundColorTop : kPageActionBackgroundColorTop; -} - -SkColor InfoBarBackground::GetBottomColor(InfoBarDelegate::Type infobar_type) { - static const SkColor kWarningBackgroundColorBottom = - SkColorSetRGB(250, 230, 145); - static const SkColor kPageActionBackgroundColorBottom = - SkColorSetRGB(179, 202, 231); - - return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? - kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; -} - void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { SkPoint gradient_points[2] = { {SkIntToScalar(0), SkIntToScalar(0)}, diff --git a/chrome/browser/ui/views/infobars/infobar_background.h b/chrome/browser/ui/views/infobars/infobar_background.h index 50bcce1..20e1df7 100644 --- a/chrome/browser/ui/views/infobars/infobar_background.h +++ b/chrome/browser/ui/views/infobars/infobar_background.h @@ -15,8 +15,6 @@ class InfoBarBackground : public views::Background { virtual ~InfoBarBackground(); void set_separator_color(SkColor color) { separator_color_ = color; } - static SkColor GetTopColor(InfoBarDelegate::Type infobar_type); - static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type); private: // views::Background: diff --git a/skia/ext/skia_utils_mac.h b/skia/ext/skia_utils_mac.h index fb9a66d..737db95 100644 --- a/skia/ext/skia_utils_mac.h +++ b/skia/ext/skia_utils_mac.h @@ -26,9 +26,11 @@ typedef struct _NSSize NSSize; #ifdef __OBJC__ @class NSImage; @class NSImageRep; +@class NSColor; #else class NSImage; class NSImageRep; +class NSColor; #endif namespace gfx { @@ -62,6 +64,9 @@ SkColor CGColorRefToSkColor(CGColorRef color); // Converts ARGB to CGColorRef. CGColorRef SkColorToCGColorRef(SkColor color); +// Converts ARGB to NSColor. +NSColor* SkColorToCalibratedNSColor(SkColor color); + // Converts a CGImage to a SkBitmap. SkBitmap CGImageToSkBitmap(CGImageRef image); diff --git a/skia/ext/skia_utils_mac.mm b/skia/ext/skia_utils_mac.mm index 3c955bb..1ef5322 100644 --- a/skia/ext/skia_utils_mac.mm +++ b/skia/ext/skia_utils_mac.mm @@ -186,6 +186,14 @@ CGColorRef SkColorToCGColorRef(SkColor color) { SkColorGetA(color) / 255.0); } +// Converts ARGB to NSColor. +NSColor* SkColorToCalibratedNSColor(SkColor color) { + return [NSColor colorWithCalibratedRed:SkColorGetR(color) / 255.0 + green:SkColorGetG(color) / 255.0 + blue:SkColorGetB(color) / 255.0 + alpha:SkColorGetA(color) / 255.0]; +} + SkBitmap CGImageToSkBitmap(CGImageRef image) { if (!image) return SkBitmap(); |