summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-08 16:12:24 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-08 16:12:24 +0000
commitfce33496f0df7a85102cfaac3c7e4f29773c607a (patch)
tree0abb65e4c92e27769d33aad652ed2ba01d702835
parent6fd7e619fab8f2cc5b213eb830dd43398b98f04e (diff)
downloadchromium_src-fce33496f0df7a85102cfaac3c7e4f29773c607a.zip
chromium_src-fce33496f0df7a85102cfaac3c7e4f29773c607a.tar.gz
chromium_src-fce33496f0df7a85102cfaac3c7e4f29773c607a.tar.bz2
views: Refactor the setup of window caption buttons.
R=sky@chromium.org Review URL: https://chromiumcodereview.appspot.com/9546024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125618 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/views/window/custom_frame_view.cc60
-rw-r--r--ui/views/window/custom_frame_view.h7
2 files changed, 33 insertions, 34 deletions
diff --git a/ui/views/window/custom_frame_view.cc b/ui/views/window/custom_frame_view.cc
index 2bdd973..e32dd5f 100644
--- a/ui/views/window/custom_frame_view.cc
+++ b/ui/views/window/custom_frame_view.cc
@@ -80,9 +80,6 @@ const SkColor kDefaultColorFrameInactive = SkColorSetRGB(161, 182, 228);
CustomFrameView::CustomFrameView(Widget* frame)
: ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(new ImageButton(this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(restore_button_(new ImageButton(this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(maximize_button_(new ImageButton(this))),
- ALLOW_THIS_IN_INITIALIZER_LIST(minimize_button_(new ImageButton(this))),
window_icon_(NULL),
should_show_minmax_buttons_(false),
should_show_client_edge_(false),
@@ -90,43 +87,20 @@ CustomFrameView::CustomFrameView(Widget* frame)
frame_background_(new FrameBackground()) {
InitClass();
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
-
close_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
// Close button images will be set in LayoutWindowControls().
AddChildView(close_button_);
- restore_button_->SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE));
- restore_button_->SetImage(CustomButton::BS_NORMAL,
- rb.GetImageNamed(IDR_RESTORE).ToSkBitmap());
- restore_button_->SetImage(CustomButton::BS_HOT,
- rb.GetImageNamed(IDR_RESTORE_H).ToSkBitmap());
- restore_button_->SetImage(CustomButton::BS_PUSHED,
- rb.GetImageNamed(IDR_RESTORE_P).ToSkBitmap());
- AddChildView(restore_button_);
-
- maximize_button_->SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE));
- maximize_button_->SetImage(CustomButton::BS_NORMAL,
- rb.GetImageNamed(IDR_MAXIMIZE).ToSkBitmap());
- maximize_button_->SetImage(CustomButton::BS_HOT,
- rb.GetImageNamed(IDR_MAXIMIZE_H).ToSkBitmap());
- maximize_button_->SetImage(CustomButton::BS_PUSHED,
- rb.GetImageNamed(IDR_MAXIMIZE_P).ToSkBitmap());
- AddChildView(maximize_button_);
-
- minimize_button_->SetAccessibleName(
- l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MINIMIZE));
- minimize_button_->SetImage(CustomButton::BS_NORMAL,
- rb.GetImageNamed(IDR_MINIMIZE).ToSkBitmap());
- minimize_button_->SetImage(CustomButton::BS_HOT,
- rb.GetImageNamed(IDR_MINIMIZE_H).ToSkBitmap());
- minimize_button_->SetImage(CustomButton::BS_PUSHED,
- rb.GetImageNamed(IDR_MINIMIZE_P).ToSkBitmap());
- AddChildView(minimize_button_);
+ minimize_button_ = InitWindowCaptionButton(IDS_APP_ACCNAME_MINIMIZE,
+ IDR_MINIMIZE, IDR_MINIMIZE_H, IDR_MINIMIZE_P);
+
+ maximize_button_ = InitWindowCaptionButton(IDS_APP_ACCNAME_MAXIMIZE,
+ IDR_MAXIMIZE, IDR_MAXIMIZE_H, IDR_MAXIMIZE_P);
+
+ restore_button_ = InitWindowCaptionButton(IDS_APP_ACCNAME_RESTORE,
+ IDR_RESTORE, IDR_RESTORE_H, IDR_RESTORE_P);
should_show_minmax_buttons_ = frame_->widget_delegate()->CanMaximize();
should_show_client_edge_ = frame_->widget_delegate()->ShouldShowClientEdge();
@@ -549,6 +523,24 @@ void CustomFrameView::LayoutClientView() {
std::max(0, height() - top_height - border_thickness));
}
+ImageButton* CustomFrameView::InitWindowCaptionButton(
+ int accessibility_string_id,
+ int normal_image_id,
+ int hot_image_id,
+ int pushed_image_id) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ ImageButton* button = new ImageButton(this);
+ button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id));
+ button->SetImage(CustomButton::BS_NORMAL,
+ rb.GetImageNamed(normal_image_id).ToSkBitmap());
+ button->SetImage(CustomButton::BS_HOT,
+ rb.GetImageNamed(hot_image_id).ToSkBitmap());
+ button->SetImage(CustomButton::BS_PUSHED,
+ rb.GetImageNamed(pushed_image_id).ToSkBitmap());
+ AddChildView(button);
+ return button;
+}
+
// static
void CustomFrameView::InitClass() {
static bool initialized = false;
diff --git a/ui/views/window/custom_frame_view.h b/ui/views/window/custom_frame_view.h
index ecea64b8..57b2ce9 100644
--- a/ui/views/window/custom_frame_view.h
+++ b/ui/views/window/custom_frame_view.h
@@ -103,6 +103,13 @@ class CustomFrameView : public NonClientFrameView,
void LayoutTitleBar();
void LayoutClientView();
+ // Creates, adds and returns a new window caption button (e.g, minimize,
+ // maximize, restore).
+ ImageButton* InitWindowCaptionButton(int accessibility_string_id,
+ int normal_image_id,
+ int hot_image_id,
+ int pushed_image_id);
+
// The bounds of the client view, in this view's coordinates.
gfx::Rect client_view_bounds_;