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 "ui/base/hit_test.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/font.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/image/image.h"
18 #include "ui/gfx/path.h"
19 #include "ui/resources/grit/ui_resources.h"
20 #include "ui/strings/grit/ui_strings.h"
21 #include "ui/views/color_constants.h"
22 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/resources/grit/views_resources.h"
24 #include "ui/views/views_delegate.h"
25 #include "ui/views/widget/native_widget_private.h"
26 #include "ui/views/widget/widget.h"
27 #include "ui/views/widget/widget_delegate.h"
28 #include "ui/views/window/client_view.h"
29 #include "ui/views/window/frame_background.h"
30 #include "ui/views/window/window_button_order_provider.h"
31 #include "ui/views/window/window_resources.h"
32 #include "ui/views/window/window_shape.h"
38 // The frame border is only visible in restored mode and is hardcoded to 4 px on
39 // each side regardless of the system window border size.
40 const int kFrameBorderThickness
= 4;
41 // In the window corners, the resize areas don't actually expand bigger, but the
42 // 16 px at the end of each edge triggers diagonal resizing.
43 const int kResizeAreaCornerSize
= 16;
44 // The titlebar never shrinks too short to show the caption button plus some
46 const int kCaptionButtonHeightWithPadding
= 19;
47 // The titlebar has a 2 px 3D edge along the top and bottom.
48 const int kTitlebarTopAndBottomEdgeThickness
= 2;
49 // The icon is inset 2 px from the left frame border.
50 const int kIconLeftSpacing
= 2;
51 // The space between the window icon and the title text.
52 const int kTitleIconOffsetX
= 4;
53 // The space between the title text and the caption buttons.
54 const int kTitleCaptionSpacing
= 5;
57 // The icon never shrinks below 16 px on a side.
58 const int kIconMinimumSize
= 16;
61 #if defined(OS_CHROMEOS)
62 // Chrome OS uses a dark gray.
63 const SkColor kDefaultColorFrame
= SkColorSetRGB(109, 109, 109);
64 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(176, 176, 176);
66 // Windows and Linux use a blue.
67 const SkColor kDefaultColorFrame
= SkColorSetRGB(66, 116, 201);
68 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(161, 182, 228);
71 const gfx::FontList
& GetTitleFontList() {
72 static const gfx::FontList title_font_list
=
73 internal::NativeWidgetPrivate::GetWindowTitleFontList();
74 return title_font_list
;
77 void LayoutButton(ImageButton
* button
, const gfx::Rect
& bounds
) {
78 button
->SetVisible(true);
79 button
->SetImageAlignment(ImageButton::ALIGN_LEFT
,
80 ImageButton::ALIGN_BOTTOM
);
81 button
->SetBoundsRect(bounds
);
86 ///////////////////////////////////////////////////////////////////////////////
87 // CustomFrameView, public:
89 CustomFrameView::CustomFrameView()
92 minimize_button_(NULL
),
93 maximize_button_(NULL
),
94 restore_button_(NULL
),
96 frame_background_(new FrameBackground()),
97 minimum_title_bar_x_(0),
98 maximum_title_bar_x_(-1) {
101 CustomFrameView::~CustomFrameView() {
104 void CustomFrameView::Init(Widget
* frame
) {
107 close_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_CLOSE
,
108 IDR_CLOSE
, IDR_CLOSE_H
, IDR_CLOSE_P
);
109 minimize_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_MINIMIZE
,
110 IDR_MINIMIZE
, IDR_MINIMIZE_H
, IDR_MINIMIZE_P
);
111 maximize_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_MAXIMIZE
,
112 IDR_MAXIMIZE
, IDR_MAXIMIZE_H
, IDR_MAXIMIZE_P
);
113 restore_button_
= InitWindowCaptionButton(IDS_APP_ACCNAME_RESTORE
,
114 IDR_RESTORE
, IDR_RESTORE_H
, IDR_RESTORE_P
);
116 if (frame_
->widget_delegate()->ShouldShowWindowIcon()) {
117 window_icon_
= new ImageButton(this);
118 AddChildView(window_icon_
);
122 ///////////////////////////////////////////////////////////////////////////////
123 // CustomFrameView, NonClientFrameView implementation:
125 gfx::Rect
CustomFrameView::GetBoundsForClientView() const {
126 return client_view_bounds_
;
129 gfx::Rect
CustomFrameView::GetWindowBoundsForClientBounds(
130 const gfx::Rect
& client_bounds
) const {
131 int top_height
= NonClientTopBorderHeight();
132 int border_thickness
= NonClientBorderThickness();
133 return gfx::Rect(client_bounds
.x() - border_thickness
,
134 client_bounds
.y() - top_height
,
135 client_bounds
.width() + (2 * border_thickness
),
136 client_bounds
.height() + top_height
+ border_thickness
);
139 int CustomFrameView::NonClientHitTest(const gfx::Point
& point
) {
141 if (!bounds().Contains(point
))
144 int frame_component
= frame_
->client_view()->NonClientHitTest(point
);
146 // See if we're in the sysmenu region. (We check the ClientView first to be
147 // consistent with OpaqueBrowserFrameView; it's not really necessary here.)
148 gfx::Rect
sysmenu_rect(IconBounds());
149 // In maximized mode we extend the rect to the screen corner to take advantage
151 if (frame_
->IsMaximized())
152 sysmenu_rect
.SetRect(0, 0, sysmenu_rect
.right(), sysmenu_rect
.bottom());
153 sysmenu_rect
.set_x(GetMirroredXForRect(sysmenu_rect
));
154 if (sysmenu_rect
.Contains(point
))
155 return (frame_component
== HTCLIENT
) ? HTCLIENT
: HTSYSMENU
;
157 if (frame_component
!= HTNOWHERE
)
158 return frame_component
;
160 // Then see if the point is within any of the window controls.
161 if (close_button_
->GetMirroredBounds().Contains(point
))
163 if (restore_button_
->GetMirroredBounds().Contains(point
))
165 if (maximize_button_
->GetMirroredBounds().Contains(point
))
167 if (minimize_button_
->GetMirroredBounds().Contains(point
))
169 if (window_icon_
&& window_icon_
->GetMirroredBounds().Contains(point
))
172 int window_component
= GetHTComponentForFrame(point
, FrameBorderThickness(),
173 NonClientBorderThickness(), kResizeAreaCornerSize
, kResizeAreaCornerSize
,
174 frame_
->widget_delegate()->CanResize());
175 // Fall back to the caption if no other component matches.
176 return (window_component
== HTNOWHERE
) ? HTCAPTION
: window_component
;
179 void CustomFrameView::GetWindowMask(const gfx::Size
& size
,
180 gfx::Path
* window_mask
) {
182 if (frame_
->IsMaximized() || !ShouldShowTitleBarAndBorder())
185 GetDefaultWindowMask(size
, window_mask
);
188 void CustomFrameView::ResetWindowControls() {
189 restore_button_
->SetState(CustomButton::STATE_NORMAL
);
190 minimize_button_
->SetState(CustomButton::STATE_NORMAL
);
191 maximize_button_
->SetState(CustomButton::STATE_NORMAL
);
192 // The close button isn't affected by this constraint.
195 void CustomFrameView::UpdateWindowIcon() {
197 window_icon_
->SchedulePaint();
200 void CustomFrameView::UpdateWindowTitle() {
201 if (frame_
->widget_delegate()->ShouldShowWindowTitle())
202 SchedulePaintInRect(title_bounds_
);
205 void CustomFrameView::SizeConstraintsChanged() {
206 ResetWindowControls();
207 LayoutWindowControls();
210 ///////////////////////////////////////////////////////////////////////////////
211 // CustomFrameView, View overrides:
213 void CustomFrameView::OnPaint(gfx::Canvas
* canvas
) {
214 if (!ShouldShowTitleBarAndBorder())
217 if (frame_
->IsMaximized())
218 PaintMaximizedFrameBorder(canvas
);
220 PaintRestoredFrameBorder(canvas
);
221 PaintTitleBar(canvas
);
222 if (ShouldShowClientEdge())
223 PaintRestoredClientEdge(canvas
);
226 void CustomFrameView::Layout() {
227 if (ShouldShowTitleBarAndBorder()) {
228 LayoutWindowControls();
235 gfx::Size
CustomFrameView::GetPreferredSize() const {
236 return frame_
->non_client_view()->GetWindowBoundsForClientBounds(
237 gfx::Rect(frame_
->client_view()->GetPreferredSize())).size();
240 gfx::Size
CustomFrameView::GetMinimumSize() const {
241 return frame_
->non_client_view()->GetWindowBoundsForClientBounds(
242 gfx::Rect(frame_
->client_view()->GetMinimumSize())).size();
245 gfx::Size
CustomFrameView::GetMaximumSize() const {
246 gfx::Size max_size
= frame_
->client_view()->GetMaximumSize();
247 gfx::Size converted_size
=
248 frame_
->non_client_view()->GetWindowBoundsForClientBounds(
249 gfx::Rect(max_size
)).size();
250 return gfx::Size(max_size
.width() == 0 ? 0 : converted_size
.width(),
251 max_size
.height() == 0 ? 0 : converted_size
.height());
254 ///////////////////////////////////////////////////////////////////////////////
255 // CustomFrameView, ButtonListener implementation:
257 void CustomFrameView::ButtonPressed(Button
* sender
, const ui::Event
& event
) {
258 if (sender
== close_button_
)
260 else if (sender
== minimize_button_
)
262 else if (sender
== maximize_button_
)
264 else if (sender
== restore_button_
)
268 ///////////////////////////////////////////////////////////////////////////////
269 // CustomFrameView, private:
271 int CustomFrameView::FrameBorderThickness() const {
272 return frame_
->IsMaximized() ? 0 : kFrameBorderThickness
;
275 int CustomFrameView::NonClientBorderThickness() const {
276 // In maximized mode, we don't show a client edge.
277 return FrameBorderThickness() +
278 (ShouldShowClientEdge() ? kClientEdgeThickness
: 0);
281 int CustomFrameView::NonClientTopBorderHeight() const {
282 return std::max(FrameBorderThickness() + IconSize(),
283 CaptionButtonY() + kCaptionButtonHeightWithPadding
) +
284 TitlebarBottomThickness();
287 int CustomFrameView::CaptionButtonY() const {
288 // Maximized buttons start at window top so that even if their images aren't
289 // drawn flush with the screen edge, they still obey Fitts' Law.
290 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
291 return FrameBorderThickness();
293 return frame_
->IsMaximized() ? FrameBorderThickness() : kFrameShadowThickness
;
297 int CustomFrameView::TitlebarBottomThickness() const {
298 return kTitlebarTopAndBottomEdgeThickness
+
299 (ShouldShowClientEdge() ? kClientEdgeThickness
: 0);
302 int CustomFrameView::IconSize() const {
304 // This metric scales up if either the titlebar height or the titlebar font
305 // size are increased.
306 return GetSystemMetrics(SM_CYSMICON
);
308 return std::max(GetTitleFontList().GetHeight(), kIconMinimumSize
);
312 gfx::Rect
CustomFrameView::IconBounds() const {
313 int size
= IconSize();
314 int frame_thickness
= FrameBorderThickness();
315 // Our frame border has a different "3D look" than Windows'. Theirs has a
316 // more complex gradient on the top that they push their icon/title below;
317 // then the maximized window cuts this off and the icon/title are centered
318 // in the remaining space. Because the apparent shape of our border is
319 // simpler, using the same positioning makes things look slightly uncentered
320 // with restored windows, so when the window is restored, instead of
321 // calculating the remaining space from below the frame border, we calculate
322 // from below the 3D edge.
323 int unavailable_px_at_top
= frame_
->IsMaximized() ?
324 frame_thickness
: kTitlebarTopAndBottomEdgeThickness
;
325 // When the icon is shorter than the minimum space we reserve for the caption
326 // button, we vertically center it. We want to bias rounding to put extra
327 // space above the icon, since the 3D edge (+ client edge, for restored
328 // windows) below looks (to the eye) more like additional space than does the
329 // 3D edge (or nothing at all, for maximized windows) above; hence the +1.
330 int y
= unavailable_px_at_top
+ (NonClientTopBorderHeight() -
331 unavailable_px_at_top
- size
- TitlebarBottomThickness() + 1) / 2;
332 return gfx::Rect(frame_thickness
+ kIconLeftSpacing
+ minimum_title_bar_x_
,
336 bool CustomFrameView::ShouldShowTitleBarAndBorder() const {
337 if (frame_
->IsFullscreen())
340 if (ViewsDelegate::GetInstance()) {
341 return !ViewsDelegate::GetInstance()->WindowManagerProvidesTitleBar(
342 frame_
->IsMaximized());
348 bool CustomFrameView::ShouldShowClientEdge() const {
349 return !frame_
->IsMaximized() && ShouldShowTitleBarAndBorder();
352 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas
* canvas
) {
353 frame_background_
->set_frame_color(GetFrameColor());
354 const gfx::ImageSkia
* frame_image
= GetFrameImage();
355 frame_background_
->set_theme_image(frame_image
);
356 frame_background_
->set_top_area_height(frame_image
->height());
358 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
360 frame_background_
->SetCornerImages(
361 rb
.GetImageNamed(IDR_WINDOW_TOP_LEFT_CORNER
).ToImageSkia(),
362 rb
.GetImageNamed(IDR_WINDOW_TOP_RIGHT_CORNER
).ToImageSkia(),
363 rb
.GetImageNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER
).ToImageSkia(),
364 rb
.GetImageNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER
).ToImageSkia());
365 frame_background_
->SetSideImages(
366 rb
.GetImageNamed(IDR_WINDOW_LEFT_SIDE
).ToImageSkia(),
367 rb
.GetImageNamed(IDR_WINDOW_TOP_CENTER
).ToImageSkia(),
368 rb
.GetImageNamed(IDR_WINDOW_RIGHT_SIDE
).ToImageSkia(),
369 rb
.GetImageNamed(IDR_WINDOW_BOTTOM_CENTER
).ToImageSkia());
371 frame_background_
->PaintRestored(canvas
, this);
374 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas
* canvas
) {
375 const gfx::ImageSkia
* frame_image
= GetFrameImage();
376 frame_background_
->set_theme_image(frame_image
);
377 frame_background_
->set_top_area_height(frame_image
->height());
378 frame_background_
->PaintMaximized(canvas
, this);
380 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
382 // TODO(jamescook): Migrate this into FrameBackground.
383 // The bottom of the titlebar actually comes from the top of the Client Edge
384 // graphic, with the actual client edge clipped off the bottom.
385 const gfx::ImageSkia
* titlebar_bottom
= rb
.GetImageNamed(
386 IDR_APP_TOP_CENTER
).ToImageSkia();
387 int edge_height
= titlebar_bottom
->height() -
388 (ShouldShowClientEdge() ? kClientEdgeThickness
: 0);
389 canvas
->TileImageInt(*titlebar_bottom
, 0,
390 frame_
->client_view()->y() - edge_height
, width(), edge_height
);
393 void CustomFrameView::PaintTitleBar(gfx::Canvas
* canvas
) {
394 WidgetDelegate
* delegate
= frame_
->widget_delegate();
396 // It seems like in some conditions we can be asked to paint after the window
397 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The
398 // correct long term fix may be to shut down the RootView in WM_DESTROY.
399 if (!delegate
|| !delegate
->ShouldShowWindowTitle())
402 gfx::Rect rect
= title_bounds_
;
403 rect
.set_x(GetMirroredXForRect(title_bounds_
));
404 canvas
->DrawStringRect(delegate
->GetWindowTitle(), GetTitleFontList(),
405 SK_ColorWHITE
, rect
);
408 void CustomFrameView::PaintRestoredClientEdge(gfx::Canvas
* canvas
) {
409 gfx::Rect client_area_bounds
= frame_
->client_view()->bounds();
410 // The shadows have a 1 pixel gap on the inside, so draw them 1 pixel inwards.
411 gfx::Rect shadowed_area_bounds
= client_area_bounds
;
412 shadowed_area_bounds
.Inset(gfx::Insets(1, 1, 1, 1));
413 int shadowed_area_top
= shadowed_area_bounds
.y();
415 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
417 // Top: left, center, right sides.
418 const gfx::ImageSkia
* top_left
= rb
.GetImageSkiaNamed(IDR_APP_TOP_LEFT
);
419 const gfx::ImageSkia
* top_center
= rb
.GetImageSkiaNamed(IDR_APP_TOP_CENTER
);
420 const gfx::ImageSkia
* top_right
= rb
.GetImageSkiaNamed(IDR_APP_TOP_RIGHT
);
421 int top_edge_y
= shadowed_area_top
- top_center
->height();
422 canvas
->DrawImageInt(*top_left
,
423 shadowed_area_bounds
.x() - top_left
->width(),
425 canvas
->TileImageInt(*top_center
,
426 shadowed_area_bounds
.x(),
428 shadowed_area_bounds
.width(),
429 top_center
->height());
430 canvas
->DrawImageInt(*top_right
, shadowed_area_bounds
.right(), top_edge_y
);
433 const gfx::ImageSkia
* right
= rb
.GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE
);
434 int shadowed_area_bottom
=
435 std::max(shadowed_area_top
, shadowed_area_bounds
.bottom());
436 int shadowed_area_height
= shadowed_area_bottom
- shadowed_area_top
;
437 canvas
->TileImageInt(*right
,
438 shadowed_area_bounds
.right(),
441 shadowed_area_height
);
443 // Bottom: left, center, right sides.
444 const gfx::ImageSkia
* bottom_left
=
445 rb
.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER
);
446 const gfx::ImageSkia
* bottom_center
=
447 rb
.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER
);
448 const gfx::ImageSkia
* bottom_right
=
449 rb
.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER
);
451 canvas
->DrawImageInt(*bottom_left
,
452 shadowed_area_bounds
.x() - bottom_left
->width(),
453 shadowed_area_bottom
);
455 canvas
->TileImageInt(*bottom_center
,
456 shadowed_area_bounds
.x(),
457 shadowed_area_bottom
,
458 shadowed_area_bounds
.width(),
459 bottom_right
->height());
461 canvas
->DrawImageInt(*bottom_right
,
462 shadowed_area_bounds
.right(),
463 shadowed_area_bottom
);
465 const gfx::ImageSkia
* left
= rb
.GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE
);
466 canvas
->TileImageInt(*left
,
467 shadowed_area_bounds
.x() - left
->width(),
470 shadowed_area_height
);
473 SkColor
CustomFrameView::GetFrameColor() const {
474 return frame_
->IsActive() ? kDefaultColorFrame
: kDefaultColorFrameInactive
;
477 const gfx::ImageSkia
* CustomFrameView::GetFrameImage() const {
478 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
479 frame_
->IsActive() ? IDR_FRAME
: IDR_FRAME_INACTIVE
).ToImageSkia();
482 void CustomFrameView::LayoutWindowControls() {
483 minimum_title_bar_x_
= 0;
484 maximum_title_bar_x_
= width();
486 if (bounds().IsEmpty())
489 int caption_y
= CaptionButtonY();
490 bool is_maximized
= frame_
->IsMaximized();
491 // There should always be the same number of non-shadow pixels visible to the
492 // side of the caption buttons. In maximized mode we extend the edge button
493 // to the screen corner to obey Fitts' Law.
494 int extra_width
= is_maximized
?
495 (kFrameBorderThickness
- kFrameShadowThickness
) : 0;
496 int next_button_x
= FrameBorderThickness();
498 bool is_restored
= !is_maximized
&& !frame_
->IsMinimized();
499 ImageButton
* invisible_button
= is_restored
? restore_button_
501 invisible_button
->SetVisible(false);
503 WindowButtonOrderProvider
* button_order
=
504 WindowButtonOrderProvider::GetInstance();
505 const std::vector
<views::FrameButton
>& leading_buttons
=
506 button_order
->leading_buttons();
507 const std::vector
<views::FrameButton
>& trailing_buttons
=
508 button_order
->trailing_buttons();
510 ImageButton
* button
= NULL
;
511 for (std::vector
<views::FrameButton
>::const_iterator it
=
512 leading_buttons
.begin(); it
!= leading_buttons
.end(); ++it
) {
513 button
= GetImageButton(*it
);
516 gfx::Rect
target_bounds(gfx::Point(next_button_x
, caption_y
),
517 button
->GetPreferredSize());
518 if (it
== leading_buttons
.begin())
519 target_bounds
.set_width(target_bounds
.width() + extra_width
);
520 LayoutButton(button
, target_bounds
);
521 next_button_x
+= button
->width();
522 minimum_title_bar_x_
= std::min(width(), next_button_x
);
525 // Trailing buttions are laid out in a RTL fashion
526 next_button_x
= width() - FrameBorderThickness();
527 for (std::vector
<views::FrameButton
>::const_reverse_iterator it
=
528 trailing_buttons
.rbegin(); it
!= trailing_buttons
.rend(); ++it
) {
529 button
= GetImageButton(*it
);
532 gfx::Rect
target_bounds(gfx::Point(next_button_x
, caption_y
),
533 button
->GetPreferredSize());
534 if (it
== trailing_buttons
.rbegin())
535 target_bounds
.set_width(target_bounds
.width() + extra_width
);
536 target_bounds
.Offset(-target_bounds
.width(), 0);
537 LayoutButton(button
, target_bounds
);
538 next_button_x
= button
->x();
539 maximum_title_bar_x_
= std::max(minimum_title_bar_x_
, next_button_x
);
543 void CustomFrameView::LayoutTitleBar() {
544 DCHECK_GE(maximum_title_bar_x_
, 0);
545 // The window title position is calculated based on the icon position, even
546 // when there is no icon.
547 gfx::Rect
icon_bounds(IconBounds());
548 bool show_window_icon
= window_icon_
!= NULL
;
549 if (show_window_icon
)
550 window_icon_
->SetBoundsRect(icon_bounds
);
552 if (!frame_
->widget_delegate()->ShouldShowWindowTitle())
555 // The offset between the window left edge and the title text.
556 int title_x
= show_window_icon
? icon_bounds
.right() + kTitleIconOffsetX
558 int title_height
= GetTitleFontList().GetHeight();
559 // We bias the title position so that when the difference between the icon and
560 // title heights is odd, the extra pixel of the title is above the vertical
561 // midline rather than below. This compensates for how the icon is already
562 // biased downwards (see IconBounds()) and helps prevent descenders on the
563 // title from overlapping the 3D edge at the bottom of the titlebar.
564 title_bounds_
.SetRect(title_x
,
565 icon_bounds
.y() + ((icon_bounds
.height() - title_height
- 1) / 2),
566 std::max(0, maximum_title_bar_x_
- kTitleCaptionSpacing
-
567 title_x
), title_height
);
570 void CustomFrameView::LayoutClientView() {
571 if (!ShouldShowTitleBarAndBorder()) {
572 client_view_bounds_
= bounds();
576 int top_height
= NonClientTopBorderHeight();
577 int border_thickness
= NonClientBorderThickness();
578 client_view_bounds_
.SetRect(border_thickness
, top_height
,
579 std::max(0, width() - (2 * border_thickness
)),
580 std::max(0, height() - top_height
- border_thickness
));
583 ImageButton
* CustomFrameView::InitWindowCaptionButton(
584 int accessibility_string_id
,
587 int pushed_image_id
) {
588 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
589 ImageButton
* button
= new ImageButton(this);
590 button
->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id
));
591 button
->SetImage(CustomButton::STATE_NORMAL
,
592 rb
.GetImageNamed(normal_image_id
).ToImageSkia());
593 button
->SetImage(CustomButton::STATE_HOVERED
,
594 rb
.GetImageNamed(hot_image_id
).ToImageSkia());
595 button
->SetImage(CustomButton::STATE_PRESSED
,
596 rb
.GetImageNamed(pushed_image_id
).ToImageSkia());
597 AddChildView(button
);
601 ImageButton
* CustomFrameView::GetImageButton(views::FrameButton frame_button
) {
602 ImageButton
* button
= NULL
;
603 switch (frame_button
) {
604 case views::FRAME_BUTTON_MINIMIZE
: {
605 button
= minimize_button_
;
606 // If we should not show the minimize button, then we return NULL as we
607 // don't want this button to become visible and to be laid out.
608 bool should_show
= frame_
->widget_delegate()->CanMinimize();
609 button
->SetVisible(should_show
);
615 case views::FRAME_BUTTON_MAXIMIZE
: {
616 bool is_restored
= !frame_
->IsMaximized() && !frame_
->IsMinimized();
617 button
= is_restored
? maximize_button_
: restore_button_
;
618 // If we should not show the maximize/restore button, then we return
619 // NULL as we don't want this button to become visible and to be laid
621 bool should_show
= frame_
->widget_delegate()->CanMaximize();
622 button
->SetVisible(should_show
);
628 case views::FRAME_BUTTON_CLOSE
: {
629 button
= close_button_
;