diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-09 00:11:45 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-09 00:11:45 +0000 |
commit | d2e34d8219af1f8fa315455f41e98d8f7c498555 (patch) | |
tree | 870125905094025d47a6c234621e06d845c83469 | |
parent | 166f20ff846640059ddd7431a5a8ef93df09f4fe (diff) | |
download | chromium_src-d2e34d8219af1f8fa315455f41e98d8f7c498555.zip chromium_src-d2e34d8219af1f8fa315455f41e98d8f7c498555.tar.gz chromium_src-d2e34d8219af1f8fa315455f41e98d8f7c498555.tar.bz2 |
cros: Fix theme window frames to not paint transparent
We were painting the theme frame image with transparency, which made it almost invisible in solo-window mode, then painting the theme overlay fully opaque. This lead to incorrect rendering of many themes. We now follow the pattern we use for Windows Aero glass - all theme images are drawn fully opaque.
Also, some themes don't supply inactive versions of their theme_frame image, and rely on the theme pack to generate one from the active image. This interfered with a hack I was doing to override the IDR_THEME_FRAME_INACTIVE ID where there wasn't a custom image supplied. I got rid of the hack and we now use the canonical IDR_THEME_FRAME_* resource IDs on Ash and I updated the default assets the version we're using.
We should probably backport this to R20, since it's a regression in theme painting and the fix is small and safe.
BUG=124095
TEST=Added FramePainterTest.GetHeaderOpacity().
R=derat@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10310065
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135951 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/wm/frame_painter.cc | 27 | ||||
-rw-r--r-- | ash/wm/frame_painter.h | 6 | ||||
-rw-r--r-- | ash/wm/frame_painter_unittest.cc | 44 | ||||
-rw-r--r-- | chrome/app/theme/ash/theme_default_active.png | bin | 8746 -> 827 bytes | |||
-rw-r--r-- | chrome/app/theme/ash/theme_default_inactive.png | bin | 5305 -> 827 bytes | |||
-rw-r--r-- | chrome/app/theme/ash/theme_incognito_active.png | bin | 8756 -> 582 bytes | |||
-rw-r--r-- | chrome/app/theme/ash/theme_incognito_inactive.png | bin | 5306 -> 582 bytes | |||
-rw-r--r-- | chrome/browser/ui/views/ash/browser_non_client_frame_view_ash.cc | 36 |
8 files changed, 82 insertions, 31 deletions
diff --git a/ash/wm/frame_painter.cc b/ash/wm/frame_painter.cc index 5c543da..6bdc426 100644 --- a/ash/wm/frame_painter.cc +++ b/ash/wm/frame_painter.cc @@ -77,6 +77,8 @@ const int kButtonOverlap = 1; const int kThemeFrameBitmapOffsetX = 5; // Duration of crossfade animation for activating and deactivating frame. const int kActivationCrossfadeDurationMs = 200; +// Alpha/opacity value for fully-opaque headers. +const int kFullyOpaque = 255; // Tiles an image into an area, rounding the top corners. Samples the |bitmap| // starting |bitmap_offset_x| pixels from the left of the image. @@ -306,10 +308,8 @@ void FramePainter::PaintHeader(views::NonClientFrameView* view, crossfade_animation_->Show(); } - int opacity = UseSoloWindowHeader() ? - kSoloWindowOpacity : - (header_mode == ACTIVE ? kActiveWindowOpacity : kInactiveWindowOpacity); - + int opacity = + GetHeaderOpacity(header_mode, theme_frame_id, theme_frame_overlay); ui::ThemeProvider* theme_provider = frame_->GetThemeProvider(); SkBitmap* theme_frame = theme_provider->GetBitmapNamed(theme_frame_id); header_frame_bounds_ = gfx::Rect(0, 0, view->width(), theme_frame->height()); @@ -571,6 +571,25 @@ int FramePainter::GetTitleOffsetX() const { kTitleNoIconOffsetX; } +int FramePainter::GetHeaderOpacity(HeaderMode header_mode, + int theme_frame_id, + const SkBitmap* theme_frame_overlay) { + // User-provided themes are painted fully opaque. + if (frame_->GetThemeProvider()->HasCustomImage(theme_frame_id)) + return kFullyOpaque; + if (theme_frame_overlay) + return kFullyOpaque; + + // Single browser window is very transparent. + if (UseSoloWindowHeader()) + return kSoloWindowOpacity; + + // Otherwise, change transparency based on window activation status. + if (header_mode == ACTIVE) + return kActiveWindowOpacity; + return kInactiveWindowOpacity; +} + // static bool FramePainter::UseSoloWindowHeader() { int window_count = 0; diff --git a/ash/wm/frame_painter.h b/ash/wm/frame_painter.h index c61102e..883d671 100644 --- a/ash/wm/frame_painter.h +++ b/ash/wm/frame_painter.h @@ -120,6 +120,7 @@ class ASH_EXPORT FramePainter : public aura::WindowObserver, private: FRIEND_TEST_ALL_PREFIXES(FramePainterTest, Basics); FRIEND_TEST_ALL_PREFIXES(FramePainterTest, UseSoloWindowHeader); + FRIEND_TEST_ALL_PREFIXES(FramePainterTest, GetHeaderOpacity); // Sets the images for a button base on IDs from the |frame_| theme provider. void SetButtonImages(views::ImageButton* button, @@ -130,6 +131,11 @@ class ASH_EXPORT FramePainter : public aura::WindowObserver, // Returns the offset between window left edge and title string. int GetTitleOffsetX() const; + // Returns the opacity value used to paint the header. + int GetHeaderOpacity(HeaderMode header_mode, + int theme_frame_id, + const SkBitmap* theme_frame_overlay); + // Returns true if there is exactly one visible, normal-type window using // a header painted by this class, in which case we should paint a transparent // window header. diff --git a/ash/wm/frame_painter_unittest.cc b/ash/wm/frame_painter_unittest.cc index dfef932..234d11f 100644 --- a/ash/wm/frame_painter_unittest.cc +++ b/ash/wm/frame_painter_unittest.cc @@ -8,6 +8,7 @@ #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" #include "base/memory/scoped_ptr.h" +#include "grit/ui_resources.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/root_window.h" #include "ui/views/controls/button/image_button.h" @@ -127,4 +128,47 @@ TEST_F(FramePainterTest, UseSoloWindowHeader) { EXPECT_FALSE(FramePainter::UseSoloWindowHeader()); } +TEST_F(FramePainterTest, GetHeaderOpacity) { + // Create a widget and a painter for it. + scoped_ptr<Widget> w1(CreateTestWidget()); + FramePainter p1; + ImageButton size1(NULL); + ImageButton close1(NULL); + p1.Init(w1.get(), NULL, &size1, &close1, FramePainter::SIZE_BUTTON_MAXIMIZES); + w1->Show(); + + // Solo active window has solo window opacity. + EXPECT_EQ(FramePainter::kSoloWindowOpacity, + p1.GetHeaderOpacity(FramePainter::ACTIVE, + IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, + NULL)); + + // Create a second widget and painter. + scoped_ptr<Widget> w2(CreateTestWidget()); + FramePainter p2; + ImageButton size2(NULL); + ImageButton close2(NULL); + p2.Init(w2.get(), NULL, &size2, &close2, FramePainter::SIZE_BUTTON_MAXIMIZES); + w2->Show(); + + // Active window has active window opacity. + EXPECT_EQ(FramePainter::kActiveWindowOpacity, + p2.GetHeaderOpacity(FramePainter::ACTIVE, + IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, + NULL)); + + // Inactive window has inactive window opacity. + EXPECT_EQ(FramePainter::kInactiveWindowOpacity, + p2.GetHeaderOpacity(FramePainter::INACTIVE, + IDR_AURA_WINDOW_HEADER_BASE_INACTIVE, + NULL)); + + // Custom overlay image is drawn completely opaque. + SkBitmap custom_overlay; + EXPECT_EQ(255, + p1.GetHeaderOpacity(FramePainter::ACTIVE, + IDR_AURA_WINDOW_HEADER_BASE_ACTIVE, + &custom_overlay)); +} + } // namespace ash diff --git a/chrome/app/theme/ash/theme_default_active.png b/chrome/app/theme/ash/theme_default_active.png Binary files differindex 780ef68..c08e7d2 100644 --- a/chrome/app/theme/ash/theme_default_active.png +++ b/chrome/app/theme/ash/theme_default_active.png diff --git a/chrome/app/theme/ash/theme_default_inactive.png b/chrome/app/theme/ash/theme_default_inactive.png Binary files differindex aad6131..c08e7d2 100644 --- a/chrome/app/theme/ash/theme_default_inactive.png +++ b/chrome/app/theme/ash/theme_default_inactive.png diff --git a/chrome/app/theme/ash/theme_incognito_active.png b/chrome/app/theme/ash/theme_incognito_active.png Binary files differindex eb1ff35..3395949 100644 --- a/chrome/app/theme/ash/theme_incognito_active.png +++ b/chrome/app/theme/ash/theme_incognito_active.png diff --git a/chrome/app/theme/ash/theme_incognito_inactive.png b/chrome/app/theme/ash/theme_incognito_inactive.png Binary files differindex f3079a0..13ba644 100644 --- a/chrome/app/theme/ash/theme_incognito_inactive.png +++ b/chrome/app/theme/ash/theme_incognito_inactive.png diff --git a/chrome/browser/ui/views/ash/browser_non_client_frame_view_ash.cc b/chrome/browser/ui/views/ash/browser_non_client_frame_view_ash.cc index a8abb56..39908a7 100644 --- a/chrome/browser/ui/views/ash/browser_non_client_frame_view_ash.cc +++ b/chrome/browser/ui/views/ash/browser_non_client_frame_view_ash.cc @@ -445,42 +445,24 @@ void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { int BrowserNonClientFrameViewAsh::GetThemeFrameBitmapId() const { bool is_incognito = browser_view()->IsOffTheRecord(); - int resource_id; if (browser_view()->IsBrowserTypeNormal()) { - ui::ThemeProvider* tp = GetThemeProvider(); + // Use the standard resource ids to allow users to theme the frames. if (ShouldPaintAsActive()) { - // Use the standard resource ids to allow users to theme the frames. - // TODO(jamescook): If this becomes the only frame we use on Aura, define - // the resources to use the standard ids like IDR_THEME_FRAME, etc. - if (is_incognito) { - return tp->HasCustomImage(IDR_THEME_FRAME_INCOGNITO) ? - IDR_THEME_FRAME_INCOGNITO : - IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE; - } - return tp->HasCustomImage(IDR_THEME_FRAME) ? - IDR_THEME_FRAME : - IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; + return is_incognito ? + IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; } - if (is_incognito) { - return tp->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE) ? - IDR_THEME_FRAME_INCOGNITO_INACTIVE : - IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_INACTIVE; - } - return tp->HasCustomImage(IDR_THEME_FRAME_INACTIVE) ? - IDR_THEME_FRAME_INACTIVE : - IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; + return is_incognito ? + IDR_THEME_FRAME_INCOGNITO_INACTIVE : IDR_THEME_FRAME_INACTIVE; } // Never theme app and popup windows. if (ShouldPaintAsActive()) { - resource_id = is_incognito ? + return is_incognito ? IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_ACTIVE : IDR_AURA_WINDOW_HEADER_BASE_ACTIVE; - } else { - resource_id = is_incognito ? - IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_INACTIVE : - IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; } - return resource_id; + return is_incognito ? + IDR_AURA_WINDOW_HEADER_BASE_INCOGNITO_INACTIVE : + IDR_AURA_WINDOW_HEADER_BASE_INACTIVE; } const SkBitmap* |