Commit 1b7050a1 authored by benwells@chromium.org's avatar benwells@chromium.org

Use light images in colored app frames, when the frame color is dark.

This makes it so the buttons can be seen against the dark background.

TBR=oshima
BUG=339558

Review URL: https://codereview.chromium.org/274013002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269577 0039d316-1c4b-4281-b951-d872f2087c98
parent aeef2f09
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
...@@ -73,10 +74,8 @@ void AppWindowFrameView::Init() { ...@@ -73,10 +74,8 @@ void AppWindowFrameView::Init() {
close_button_->SetAccessibleName( close_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
AddChildView(close_button_); AddChildView(close_button_);
// STATE_NORMAL images are set in SetButtonImagesForFrame, not here.
maximize_button_ = new views::ImageButton(this); maximize_button_ = new views::ImageButton(this);
maximize_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE).ToImageSkia());
maximize_button_->SetImage( maximize_button_->SetImage(
views::CustomButton::STATE_HOVERED, views::CustomButton::STATE_HOVERED,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_H).ToImageSkia()); rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_H).ToImageSkia());
...@@ -90,9 +89,6 @@ void AppWindowFrameView::Init() { ...@@ -90,9 +89,6 @@ void AppWindowFrameView::Init() {
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE)); l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE));
AddChildView(maximize_button_); AddChildView(maximize_button_);
restore_button_ = new views::ImageButton(this); restore_button_ = new views::ImageButton(this);
restore_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE).ToImageSkia());
restore_button_->SetImage( restore_button_->SetImage(
views::CustomButton::STATE_HOVERED, views::CustomButton::STATE_HOVERED,
rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_H).ToImageSkia()); rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_H).ToImageSkia());
...@@ -103,9 +99,6 @@ void AppWindowFrameView::Init() { ...@@ -103,9 +99,6 @@ void AppWindowFrameView::Init() {
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE)); l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE));
AddChildView(restore_button_); AddChildView(restore_button_);
minimize_button_ = new views::ImageButton(this); minimize_button_ = new views::ImageButton(this);
minimize_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE).ToImageSkia());
minimize_button_->SetImage( minimize_button_->SetImage(
views::CustomButton::STATE_HOVERED, views::CustomButton::STATE_HOVERED,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia()); rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_H).ToImageSkia());
...@@ -115,6 +108,8 @@ void AppWindowFrameView::Init() { ...@@ -115,6 +108,8 @@ void AppWindowFrameView::Init() {
minimize_button_->SetAccessibleName( minimize_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE)); l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE));
AddChildView(minimize_button_); AddChildView(minimize_button_);
SetButtonImagesForFrame();
} }
} }
...@@ -304,14 +299,12 @@ void AppWindowFrameView::OnPaint(gfx::Canvas* canvas) { ...@@ -304,14 +299,12 @@ void AppWindowFrameView::OnPaint(gfx::Canvas* canvas) {
rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia()); rb.GetNativeImageNamed(IDR_APP_WINDOW_CLOSE_U).ToImageSkia());
} }
// TODO(jeremya): different look for inactive? SetButtonImagesForFrame();
// TODO(benwells): different look for inactive by default.
SkPaint paint; SkPaint paint;
paint.setAntiAlias(false); paint.setAntiAlias(false);
paint.setStyle(SkPaint::kFill_Style); paint.setStyle(SkPaint::kFill_Style);
if (widget_->IsActive()) paint.setColor(CurrentFrameColor());
paint.setColor(active_frame_color_);
else
paint.setColor(inactive_frame_color_);
gfx::Path path; gfx::Path path;
path.moveTo(0, 0); path.moveTo(0, 0);
path.lineTo(width(), 0); path.lineTo(width(), 0);
...@@ -366,4 +359,42 @@ void AppWindowFrameView::ButtonPressed(views::Button* sender, ...@@ -366,4 +359,42 @@ void AppWindowFrameView::ButtonPressed(views::Button* sender,
widget_->Minimize(); widget_->Minimize();
} }
SkColor AppWindowFrameView::CurrentFrameColor() {
return widget_->IsActive() ? active_frame_color_ : inactive_frame_color_;
}
void AppWindowFrameView::SetButtonImagesForFrame() {
DCHECK(draw_frame_);
// If the frame is dark, we should use the light images so they have
// some contrast.
unsigned char frame_luma =
color_utils::GetLuminanceForColor(CurrentFrameColor());
const unsigned char kLuminanceThreshold = 100;
bool use_light = frame_luma < kLuminanceThreshold;
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (use_light) {
maximize_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE_L).ToImageSkia());
restore_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE_L).ToImageSkia());
minimize_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE_L).ToImageSkia());
} else {
maximize_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MAXIMIZE).ToImageSkia());
restore_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_RESTORE).ToImageSkia());
minimize_button_->SetImage(
views::CustomButton::STATE_NORMAL,
rb.GetNativeImageNamed(IDR_APP_WINDOW_MINIMIZE).ToImageSkia());
}
}
} // namespace apps } // namespace apps
...@@ -88,6 +88,13 @@ class AppWindowFrameView : public views::NonClientFrameView, ...@@ -88,6 +88,13 @@ class AppWindowFrameView : public views::NonClientFrameView,
virtual void ButtonPressed(views::Button* sender, virtual void ButtonPressed(views::Button* sender,
const ui::Event& event) OVERRIDE; const ui::Event& event) OVERRIDE;
// Some button images we use depend on the color of the frame. This
// will set these images based on the color of the frame.
void SetButtonImagesForFrame();
// Return the current frame color based on the active state of the window.
SkColor CurrentFrameColor();
views::Widget* widget_; views::Widget* widget_;
NativeAppWindow* window_; NativeAppWindow* window_;
bool draw_frame_; bool draw_frame_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment