1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/views/window/custom_frame_view.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "grit/ui_resources.h"
12 #include "grit/ui_strings.h"
13 #include "ui/base/hit_test.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/font.h"
18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/path.h"
20 #include "ui/gfx/rect.h"
21 #include "ui/views/color_constants.h"
22 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/views_delegate.h"
24 #include "ui/views/widget/native_widget_private.h"
25 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h"
27 #include "ui/views/window/client_view.h"
28 #include "ui/views/window/frame_background.h"
29 #include "ui/views/window/window_button_order_provider.h"
30 #include "ui/views/window/window_resources.h"
31 #include "ui/views/window/window_shape.h"
37 // The frame border is only visible in restored mode and is hardcoded to 4 px on
38 // each side regardless of the system window border size.
39 const int kFrameBorderThickness
= 4;
40 // In the window corners, the resize areas don't actually expand bigger, but the
41 // 16 px at the end of each edge triggers diagonal resizing.
42 const int kResizeAreaCornerSize
= 16;
43 // The titlebar never shrinks too short to show the caption button plus some
45 const int kCaptionButtonHeightWithPadding
= 19;
46 // The titlebar has a 2 px 3D edge along the top and bottom.
47 const int kTitlebarTopAndBottomEdgeThickness
= 2;
48 // The icon is inset 2 px from the left frame border.
49 const int kIconLeftSpacing
= 2;
50 // The icon never shrinks below 16 px on a side.
51 const int kIconMinimumSize
= 16;
52 // The space between the window icon and the title text.
53 const int kTitleIconOffsetX
= 4;
54 // The space between the title text and the caption buttons.
55 const int kTitleCaptionSpacing
= 5;
57 #if defined(OS_CHROMEOS)
58 // Chrome OS uses a dark gray.
59 const SkColor kDefaultColorFrame
= SkColorSetRGB(109, 109, 109);
60 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(176, 176, 176);
62 // Windows and Linux use a blue.
63 const SkColor kDefaultColorFrame
= SkColorSetRGB(66, 116, 201);
64 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(161, 182, 228);
67 const gfx::FontList
& GetTitleFontList() {
68 static const gfx::FontList title_font_list
=
69 internal::NativeWidgetPrivate::GetWindowTitleFontList();
70 return title_font_list
;
73 void LayoutButton(ImageButton
* button
, const gfx::Rect
& bounds
) {
74 button
->SetVisible(true);
75 button
->SetImageAlignment(ImageButton::ALIGN_LEFT
,
76 ImageButton::ALIGN_BOTTOM
);
77 button
->SetBoundsRect(bounds
);
82 ///////////////////////////////////////////////////////////////////////////////
83 // CustomFrameView, public:
85 CustomFrameView::CustomFrameView()
88 minimize_button_(NULL
),
89 maximize_button_(NULL
),
90 restore_button_(NULL
),
92 should_show_maximize_button_(false),
93 frame_background_(new FrameBackground()),
94 minimum_title_bar_x_(0),
95 maximum_title_bar_x_(-1) {
98 CustomFrameView::~CustomFrameView() {
101 void CustomFrameView::Init(Widget
* frame
) {
104 close_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_CLOSE
,
105 IDR_CLOSE
, IDR_CLOSE_H
, IDR_CLOSE_P
);
106 minimize_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_MINIMIZE
,
107 IDR_MINIMIZE
, IDR_MINIMIZE_H
, IDR_MINIMIZE_P
);
108 maximize_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_MAXIMIZE
,
109 IDR_MAXIMIZE
, IDR_MAXIMIZE_H
, IDR_MAXIMIZE_P
);
110 restore_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_RESTORE
,
111 IDR_RESTORE
, IDR_RESTORE_H
, IDR_RESTORE_P
);
113 should_show_maximize_button_
= frame_
->widget_delegate()->CanMaximize();
115 if (frame_
->widget_delegate()->ShouldShowWindowIcon()) {
116 window_icon_
= new ImageButton(this);
117 AddChildView(window_icon_
);
121 ///////////////////////////////////////////////////////////////////////////////
122 // CustomFrameView, NonClientFrameView implementation:
124 gfx::Rect
CustomFrameView::GetBoundsForClientView() const {
125 return client_view_bounds_
;
128 gfx::Rect
CustomFrameView::GetWindowBoundsForClientBounds(
129 const gfx::Rect
& client_bounds
) const {
130 int top_height
= NonClientTopBorderHeight();
131 int border_thickness
= NonClientBorderThickness();
132 return gfx::Rect(client_bounds
.x() - border_thickness
,
133 client_bounds
.y() - top_height
,
134 client_bounds
.width() + (2 * border_thickness
),
135 client_bounds
.height() + top_height
+ border_thickness
);
138 int CustomFrameView::NonClientHitTest(const gfx::Point
& point
) {
140 if (!bounds().Contains(point
))
143 int frame_component
= frame_
->client_view()->NonClientHitTest(point
);
145 // See if we're in the sysmenu region. (We check the ClientView first to be
146 // consistent with OpaqueBrowserFrameView; it's not really necessary here.)
147 gfx::Rect
sysmenu_rect(IconBounds());
148 // In maximized mode we extend the rect to the screen corner to take advantage
150 if (frame_
->IsMaximized())
151 sysmenu_rect
.SetRect(0, 0, sysmenu_rect
.right(), sysmenu_rect
.bottom());
152 sysmenu_rect
.set_x(GetMirroredXForRect(sysmenu_rect
));
153 if (sysmenu_rect
.Contains(point
))
154 return (frame_component
== HTCLIENT
) ? HTCLIENT
: HTSYSMENU
;
156 if (frame_component
!= HTNOWHERE
)
157 return frame_component
;
159 // Then see if the point is within any of the window controls.
160 if (close_button_
->GetMirroredBounds().Contains(point
))
162 if (restore_button_
->GetMirroredBounds().Contains(point
))
164 if (maximize_button_
->GetMirroredBounds().Contains(point
))
166 if (minimize_button_
->GetMirroredBounds().Contains(point
))
168 if (window_icon_
&& window_icon_
->GetMirroredBounds().Contains(point
))
171 int window_component
= GetHTComponentForFrame(point
, FrameBorderThickness(),
172 NonClientBorderThickness(), kResizeAreaCornerSize
, kResizeAreaCornerSize
,
173 frame_
->widget_delegate()->CanResize());
174 // Fall back to the caption if no other component matches.
175 return (window_component
== HTNOWHERE
) ? HTCAPTION
: window_component
;
178 void CustomFrameView::GetWindowMask(const gfx::Size
& size
,
179 gfx::Path
* window_mask
) {
181 if (frame_
->IsMaximized() || !ShouldShowTitleBarAndBorder())
184 GetDefaultWindowMask(size
, window_mask
);
187 void CustomFrameView::ResetWindowControls() {
188 restore_button_
->SetState(CustomButton::STATE_NORMAL
);
189 minimize_button_
->SetState(CustomButton::STATE_NORMAL
);
190 maximize_button_
->SetState(CustomButton::STATE_NORMAL
);
191 // The close button isn't affected by this constraint.
194 void CustomFrameView::UpdateWindowIcon() {
196 window_icon_
->SchedulePaint();
199 void CustomFrameView::UpdateWindowTitle() {
200 if (frame_
->widget_delegate()->ShouldShowWindowTitle())
201 SchedulePaintInRect(title_bounds_
);
204 ///////////////////////////////////////////////////////////////////////////////
205 // CustomFrameView, View overrides:
207 void CustomFrameView::OnPaint(gfx::Canvas
* canvas
) {
208 if (!ShouldShowTitleBarAndBorder())
211 if (frame_
->IsMaximized())
212 PaintMaximizedFrameBorder(canvas
);
214 PaintRestoredFrameBorder(canvas
);
215 PaintTitleBar(canvas
);
216 if (ShouldShowClientEdge())
217 PaintRestoredClientEdge(canvas
);
220 void CustomFrameView::Layout() {
221 if (ShouldShowTitleBarAndBorder()) {
222 LayoutWindowControls();
229 gfx::Size
CustomFrameView::GetPreferredSize() const {
230 return frame_
->non_client_view()->GetWindowBoundsForClientBounds(
231 gfx::Rect(frame_
->client_view()->GetPreferredSize())).size();
234 gfx::Size
CustomFrameView::GetMinimumSize() const {
235 return frame_
->non_client_view()->GetWindowBoundsForClientBounds(
236 gfx::Rect(frame_
->client_view()->GetMinimumSize())).size();
239 gfx::Size
CustomFrameView::GetMaximumSize() const {
240 gfx::Size max_size
= frame_
->client_view()->GetMaximumSize();
241 gfx::Size converted_size
=
242 frame_
->non_client_view()->GetWindowBoundsForClientBounds(
243 gfx::Rect(max_size
)).size();
244 return gfx::Size(max_size
.width() == 0 ? 0 : converted_size
.width(),
245 max_size
.height() == 0 ? 0 : converted_size
.height());
248 ///////////////////////////////////////////////////////////////////////////////
249 // CustomFrameView, ButtonListener implementation:
251 void CustomFrameView::ButtonPressed(Button
* sender
, const ui::Event
& event
) {
252 if (sender
== close_button_
)
254 else if (sender
== minimize_button_
)
256 else if (sender
== maximize_button_
)
258 else if (sender
== restore_button_
)
262 ///////////////////////////////////////////////////////////////////////////////
263 // CustomFrameView, private:
265 int CustomFrameView::FrameBorderThickness() const {
266 return frame_
->IsMaximized() ? 0 : kFrameBorderThickness
;
269 int CustomFrameView::NonClientBorderThickness() const {
270 // In maximized mode, we don't show a client edge.
271 return FrameBorderThickness() +
272 (ShouldShowClientEdge() ? kClientEdgeThickness
: 0);
275 int CustomFrameView::NonClientTopBorderHeight() const {
276 return std::max(FrameBorderThickness() + IconSize(),
277 CaptionButtonY() + kCaptionButtonHeightWithPadding
) +
278 TitlebarBottomThickness();
281 int CustomFrameView::CaptionButtonY() const {
282 // Maximized buttons start at window top so that even if their images aren't
283 // drawn flush with the screen edge, they still obey Fitts' Law.
284 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
285 return FrameBorderThickness();
287 return frame_
->IsMaximized() ? FrameBorderThickness() : kFrameShadowThickness
;
291 int CustomFrameView::TitlebarBottomThickness() const {
292 return kTitlebarTopAndBottomEdgeThickness
+
293 (ShouldShowClientEdge() ? kClientEdgeThickness
: 0);
296 int CustomFrameView::IconSize() const {
298 // This metric scales up if either the titlebar height or the titlebar font
299 // size are increased.
300 return GetSystemMetrics(SM_CYSMICON
);
302 return std::max(GetTitleFontList().GetHeight(), kIconMinimumSize
);
306 gfx::Rect
CustomFrameView::IconBounds() const {
307 int size
= IconSize();
308 int frame_thickness
= FrameBorderThickness();
309 // Our frame border has a different "3D look" than Windows'. Theirs has a
310 // more complex gradient on the top that they push their icon/title below;
311 // then the maximized window cuts this off and the icon/title are centered
312 // in the remaining space. Because the apparent shape of our border is
313 // simpler, using the same positioning makes things look slightly uncentered
314 // with restored windows, so when the window is restored, instead of
315 // calculating the remaining space from below the frame border, we calculate
316 // from below the 3D edge.
317 int unavailable_px_at_top
= frame_
->IsMaximized() ?
318 frame_thickness
: kTitlebarTopAndBottomEdgeThickness
;
319 // When the icon is shorter than the minimum space we reserve for the caption
320 // button, we vertically center it. We want to bias rounding to put extra
321 // space above the icon, since the 3D edge (+ client edge, for restored
322 // windows) below looks (to the eye) more like additional space than does the
323 // 3D edge (or nothing at all, for maximized windows) above; hence the +1.
324 int y
= unavailable_px_at_top
+ (NonClientTopBorderHeight() -
325 unavailable_px_at_top
- size
- TitlebarBottomThickness() + 1) / 2;
326 return gfx::Rect(frame_thickness
+ kIconLeftSpacing
+ minimum_title_bar_x_
,
330 bool CustomFrameView::ShouldShowTitleBarAndBorder() const {
331 if (frame_
->IsFullscreen())
334 if (ViewsDelegate::views_delegate
) {
335 return !ViewsDelegate::views_delegate
->WindowManagerProvidesTitleBar(
336 frame_
->IsMaximized());
342 bool CustomFrameView::ShouldShowClientEdge() const {
343 return !frame_
->IsMaximized() && ShouldShowTitleBarAndBorder();
346 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas
* canvas
) {
347 frame_background_
->set_frame_color(GetFrameColor());
348 const gfx::ImageSkia
* frame_image
= GetFrameImage();
349 frame_background_
->set_theme_image(frame_image
);
350 frame_background_
->set_top_area_height(frame_image
->height());
352 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
354 frame_background_
->SetCornerImages(
355 rb
.GetImageNamed(IDR_WINDOW_TOP_LEFT_CORNER
).ToImageSkia(),
356 rb
.GetImageNamed(IDR_WINDOW_TOP_RIGHT_CORNER
).ToImageSkia(),
357 rb
.GetImageNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER
).ToImageSkia(),
358 rb
.GetImageNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER
).ToImageSkia());
359 frame_background_
->SetSideImages(
360 rb
.GetImageNamed(IDR_WINDOW_LEFT_SIDE
).ToImageSkia(),
361 rb
.GetImageNamed(IDR_WINDOW_TOP_CENTER
).ToImageSkia(),
362 rb
.GetImageNamed(IDR_WINDOW_RIGHT_SIDE
).ToImageSkia(),
363 rb
.GetImageNamed(IDR_WINDOW_BOTTOM_CENTER
).ToImageSkia());
365 frame_background_
->PaintRestored(canvas
, this);
368 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas
* canvas
) {
369 const gfx::ImageSkia
* frame_image
= GetFrameImage();
370 frame_background_
->set_theme_image(frame_image
);
371 frame_background_
->set_top_area_height(frame_image
->height());
372 frame_background_
->PaintMaximized(canvas
, this);
374 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
376 // TODO(jamescook): Migrate this into FrameBackground.
377 // The bottom of the titlebar actually comes from the top of the Client Edge
378 // graphic, with the actual client edge clipped off the bottom.
379 const gfx::ImageSkia
* titlebar_bottom
= rb
.GetImageNamed(
380 IDR_APP_TOP_CENTER
).ToImageSkia();
381 int edge_height
= titlebar_bottom
->height() -
382 (ShouldShowClientEdge() ? kClientEdgeThickness
: 0);
383 canvas
->TileImageInt(*titlebar_bottom
, 0,
384 frame_
->client_view()->y() - edge_height
, width(), edge_height
);
387 void CustomFrameView::PaintTitleBar(gfx::Canvas
* canvas
) {
388 WidgetDelegate
* delegate
= frame_
->widget_delegate();
390 // It seems like in some conditions we can be asked to paint after the window
391 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The
392 // correct long term fix may be to shut down the RootView in WM_DESTROY.
393 if (!delegate
|| !delegate
->ShouldShowWindowTitle())
396 gfx::Rect rect
= title_bounds_
;
397 rect
.set_x(GetMirroredXForRect(title_bounds_
));
398 canvas
->DrawStringRect(delegate
->GetWindowTitle(), GetTitleFontList(),
399 SK_ColorWHITE
, rect
);
402 void CustomFrameView::PaintRestoredClientEdge(gfx::Canvas
* canvas
) {
403 gfx::Rect client_area_bounds
= frame_
->client_view()->bounds();
404 int client_area_top
= client_area_bounds
.y();
406 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
408 // Top: left, center, right sides.
409 const gfx::ImageSkia
* top_left
= rb
.GetImageSkiaNamed(IDR_APP_TOP_LEFT
);
410 const gfx::ImageSkia
* top_center
= rb
.GetImageSkiaNamed(IDR_APP_TOP_CENTER
);
411 const gfx::ImageSkia
* top_right
= rb
.GetImageSkiaNamed(IDR_APP_TOP_RIGHT
);
412 int top_edge_y
= client_area_top
- top_center
->height();
413 canvas
->DrawImageInt(*top_left
,
414 client_area_bounds
.x() - top_left
->width(),
416 canvas
->TileImageInt(*top_center
,
417 client_area_bounds
.x(),
419 client_area_bounds
.width(),
420 top_center
->height());
421 canvas
->DrawImageInt(*top_right
, client_area_bounds
.right(), top_edge_y
);
424 const gfx::ImageSkia
* right
= rb
.GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE
);
425 int client_area_bottom
=
426 std::max(client_area_top
, client_area_bounds
.bottom());
427 int client_area_height
= client_area_bottom
- client_area_top
;
428 canvas
->TileImageInt(*right
,
429 client_area_bounds
.right(),
434 // Bottom: left, center, right sides.
435 const gfx::ImageSkia
* bottom_left
=
436 rb
.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER
);
437 const gfx::ImageSkia
* bottom_center
=
438 rb
.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER
);
439 const gfx::ImageSkia
* bottom_right
=
440 rb
.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER
);
442 canvas
->DrawImageInt(*bottom_left
,
443 client_area_bounds
.x() - bottom_left
->width(),
446 canvas
->TileImageInt(*bottom_center
,
447 client_area_bounds
.x(),
449 client_area_bounds
.width(),
450 bottom_right
->height());
452 canvas
->DrawImageInt(*bottom_right
,
453 client_area_bounds
.right(),
456 const gfx::ImageSkia
* left
= rb
.GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE
);
457 canvas
->TileImageInt(*left
,
458 client_area_bounds
.x() - left
->width(),
463 // Draw the color to fill in the edges.
464 canvas
->FillRect(gfx::Rect(client_area_bounds
.x() - 1,
466 client_area_bounds
.width() + 1,
467 client_area_bottom
- client_area_top
+ 1),
471 SkColor
CustomFrameView::GetFrameColor() const {
472 return frame_
->IsActive() ? kDefaultColorFrame
: kDefaultColorFrameInactive
;
475 const gfx::ImageSkia
* CustomFrameView::GetFrameImage() const {
476 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
477 frame_
->IsActive() ? IDR_FRAME
: IDR_FRAME_INACTIVE
).ToImageSkia();
480 void CustomFrameView::LayoutWindowControls() {
481 minimum_title_bar_x_
= 0;
482 maximum_title_bar_x_
= width();
484 if (bounds().IsEmpty())
487 int caption_y
= CaptionButtonY();
488 bool is_maximized
= frame_
->IsMaximized();
489 // There should always be the same number of non-shadow pixels visible to the
490 // side of the caption buttons. In maximized mode we extend the edge button
491 // to the screen corner to obey Fitts' Law.
492 int extra_width
= is_maximized
?
493 (kFrameBorderThickness
- kFrameShadowThickness
) : 0;
494 int next_button_x
= FrameBorderThickness();
496 bool is_restored
= !is_maximized
&& !frame_
->IsMinimized();
497 ImageButton
* invisible_button
= is_restored
? restore_button_
499 invisible_button
->SetVisible(false);
501 WindowButtonOrderProvider
* button_order
=
502 WindowButtonOrderProvider::GetInstance();
503 const std::vector
<views::FrameButton
>& leading_buttons
=
504 button_order
->leading_buttons();
505 const std::vector
<views::FrameButton
>& trailing_buttons
=
506 button_order
->trailing_buttons();
508 ImageButton
* button
= NULL
;
509 for (std::vector
<views::FrameButton
>::const_iterator it
=
510 leading_buttons
.begin(); it
!= leading_buttons
.end(); ++it
) {
511 button
= GetImageButton(*it
);
514 gfx::Rect
target_bounds(gfx::Point(next_button_x
, caption_y
),
515 button
->GetPreferredSize());
516 if (it
== leading_buttons
.begin())
517 target_bounds
.set_width(target_bounds
.width() + extra_width
);
518 LayoutButton(button
, target_bounds
);
519 next_button_x
+= button
->width();
520 minimum_title_bar_x_
= std::min(width(), next_button_x
);
523 // Trailing buttions are laid out in a RTL fashion
524 next_button_x
= width() - FrameBorderThickness();
525 for (std::vector
<views::FrameButton
>::const_reverse_iterator it
=
526 trailing_buttons
.rbegin(); it
!= trailing_buttons
.rend(); ++it
) {
527 button
= GetImageButton(*it
);
530 gfx::Rect
target_bounds(gfx::Point(next_button_x
, caption_y
),
531 button
->GetPreferredSize());
532 if (it
== trailing_buttons
.rbegin())
533 target_bounds
.set_width(target_bounds
.width() + extra_width
);
534 target_bounds
.Offset(-target_bounds
.width(), 0);
535 LayoutButton(button
, target_bounds
);
536 next_button_x
= button
->x();
537 maximum_title_bar_x_
= std::max(minimum_title_bar_x_
, next_button_x
);
541 void CustomFrameView::LayoutTitleBar() {
542 DCHECK_GE(maximum_title_bar_x_
, 0);
543 // The window title position is calculated based on the icon position, even
544 // when there is no icon.
545 gfx::Rect
icon_bounds(IconBounds());
546 bool show_window_icon
= window_icon_
!= NULL
;
547 if (show_window_icon
)
548 window_icon_
->SetBoundsRect(icon_bounds
);
550 if (!frame_
->widget_delegate()->ShouldShowWindowTitle())
553 // The offset between the window left edge and the title text.
554 int title_x
= show_window_icon
? icon_bounds
.right() + kTitleIconOffsetX
556 int title_height
= GetTitleFontList().GetHeight();
557 // We bias the title position so that when the difference between the icon and
558 // title heights is odd, the extra pixel of the title is above the vertical
559 // midline rather than below. This compensates for how the icon is already
560 // biased downwards (see IconBounds()) and helps prevent descenders on the
561 // title from overlapping the 3D edge at the bottom of the titlebar.
562 title_bounds_
.SetRect(title_x
,
563 icon_bounds
.y() + ((icon_bounds
.height() - title_height
- 1) / 2),
564 std::max(0, maximum_title_bar_x_
- kTitleCaptionSpacing
-
565 title_x
), title_height
);
568 void CustomFrameView::LayoutClientView() {
569 if (!ShouldShowTitleBarAndBorder()) {
570 client_view_bounds_
= bounds();
574 int top_height
= NonClientTopBorderHeight();
575 int border_thickness
= NonClientBorderThickness();
576 client_view_bounds_
.SetRect(border_thickness
, top_height
,
577 std::max(0, width() - (2 * border_thickness
)),
578 std::max(0, height() - top_height
- border_thickness
));
581 ImageButton
* CustomFrameView::InitWindowCaptionButton(
582 int accessibility_string_id
,
585 int pushed_image_id
) {
586 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
587 ImageButton
* button
= new ImageButton(this);
588 button
->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id
));
589 button
->SetImage(CustomButton::STATE_NORMAL
,
590 rb
.GetImageNamed(normal_image_id
).ToImageSkia());
591 button
->SetImage(CustomButton::STATE_HOVERED
,
592 rb
.GetImageNamed(hot_image_id
).ToImageSkia());
593 button
->SetImage(CustomButton::STATE_PRESSED
,
594 rb
.GetImageNamed(pushed_image_id
).ToImageSkia());
595 AddChildView(button
);
599 ImageButton
* CustomFrameView::GetImageButton(views::FrameButton frame_button
) {
600 ImageButton
* button
= NULL
;
601 switch (frame_button
) {
602 case views::FRAME_BUTTON_MINIMIZE
: {
603 button
= minimize_button_
;
606 case views::FRAME_BUTTON_MAXIMIZE
: {
607 bool is_restored
= !frame_
->IsMaximized() && !frame_
->IsMinimized();
608 button
= is_restored
? maximize_button_
: restore_button_
;
609 if (!should_show_maximize_button_
) {
610 // If we should not show the maximize/restore button, then we return
611 // NULL as we don't want this button to become visible and to be laid
613 button
->SetVisible(false);
618 case views::FRAME_BUTTON_CLOSE
: {
619 button
= close_button_
;