Move content_settings_pattern and content_settings_pattern_parser to the content_sett...
[chromium-blink-merge.git] / ui / views / window / custom_frame_view.cc
blob9ee05107d2a70a5a1874ecfa8d1baf147b89f083
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"
7 #include <algorithm>
8 #include <vector>
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/image/image.h"
17 #include "ui/gfx/path.h"
18 #include "ui/gfx/rect.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/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"
33 namespace views {
35 namespace {
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
44 // padding below it.
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);
61 #else
62 // Windows and Linux use a blue.
63 const SkColor kDefaultColorFrame = SkColorSetRGB(66, 116, 201);
64 const SkColor kDefaultColorFrameInactive = SkColorSetRGB(161, 182, 228);
65 #endif
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);
80 } // namespace
82 ///////////////////////////////////////////////////////////////////////////////
83 // CustomFrameView, public:
85 CustomFrameView::CustomFrameView()
86 : frame_(NULL),
87 window_icon_(NULL),
88 minimize_button_(NULL),
89 maximize_button_(NULL),
90 restore_button_(NULL),
91 close_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) {
102 frame_ = 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) {
139 // Sanity check.
140 if (!bounds().Contains(point))
141 return HTNOWHERE;
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
149 // of Fitts' Law.
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))
161 return HTCLOSE;
162 if (restore_button_->GetMirroredBounds().Contains(point))
163 return HTMAXBUTTON;
164 if (maximize_button_->GetMirroredBounds().Contains(point))
165 return HTMAXBUTTON;
166 if (minimize_button_->GetMirroredBounds().Contains(point))
167 return HTMINBUTTON;
168 if (window_icon_ && window_icon_->GetMirroredBounds().Contains(point))
169 return HTSYSMENU;
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) {
180 DCHECK(window_mask);
181 if (frame_->IsMaximized() || !ShouldShowTitleBarAndBorder())
182 return;
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() {
195 if (window_icon_)
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())
209 return;
211 if (frame_->IsMaximized())
212 PaintMaximizedFrameBorder(canvas);
213 else
214 PaintRestoredFrameBorder(canvas);
215 PaintTitleBar(canvas);
216 if (ShouldShowClientEdge())
217 PaintRestoredClientEdge(canvas);
220 void CustomFrameView::Layout() {
221 if (ShouldShowTitleBarAndBorder()) {
222 LayoutWindowControls();
223 LayoutTitleBar();
226 LayoutClientView();
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_)
253 frame_->Close();
254 else if (sender == minimize_button_)
255 frame_->Minimize();
256 else if (sender == maximize_button_)
257 frame_->Maximize();
258 else if (sender == restore_button_)
259 frame_->Restore();
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();
286 #else
287 return frame_->IsMaximized() ? FrameBorderThickness() : kFrameShadowThickness;
288 #endif
291 int CustomFrameView::TitlebarBottomThickness() const {
292 return kTitlebarTopAndBottomEdgeThickness +
293 (ShouldShowClientEdge() ? kClientEdgeThickness : 0);
296 int CustomFrameView::IconSize() const {
297 #if defined(OS_WIN)
298 // This metric scales up if either the titlebar height or the titlebar font
299 // size are increased.
300 return GetSystemMetrics(SM_CYSMICON);
301 #else
302 return std::max(GetTitleFontList().GetHeight(), kIconMinimumSize);
303 #endif
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_,
327 y, size, size);
330 bool CustomFrameView::ShouldShowTitleBarAndBorder() const {
331 if (frame_->IsFullscreen())
332 return false;
334 if (ViewsDelegate::views_delegate) {
335 return !ViewsDelegate::views_delegate->WindowManagerProvidesTitleBar(
336 frame_->IsMaximized());
339 return true;
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())
394 return;
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 // The shadows have a 1 pixel gap on the inside, so draw them 1 pixel inwards.
405 gfx::Rect shadowed_area_bounds = client_area_bounds;
406 shadowed_area_bounds.Inset(gfx::Insets(1, 1, 1, 1));
407 int shadowed_area_top = shadowed_area_bounds.y();
409 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
411 // Top: left, center, right sides.
412 const gfx::ImageSkia* top_left = rb.GetImageSkiaNamed(IDR_APP_TOP_LEFT);
413 const gfx::ImageSkia* top_center = rb.GetImageSkiaNamed(IDR_APP_TOP_CENTER);
414 const gfx::ImageSkia* top_right = rb.GetImageSkiaNamed(IDR_APP_TOP_RIGHT);
415 int top_edge_y = shadowed_area_top - top_center->height();
416 canvas->DrawImageInt(*top_left,
417 shadowed_area_bounds.x() - top_left->width(),
418 top_edge_y);
419 canvas->TileImageInt(*top_center,
420 shadowed_area_bounds.x(),
421 top_edge_y,
422 shadowed_area_bounds.width(),
423 top_center->height());
424 canvas->DrawImageInt(*top_right, shadowed_area_bounds.right(), top_edge_y);
426 // Right side.
427 const gfx::ImageSkia* right = rb.GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE);
428 int shadowed_area_bottom =
429 std::max(shadowed_area_top, shadowed_area_bounds.bottom());
430 int shadowed_area_height = shadowed_area_bottom - shadowed_area_top;
431 canvas->TileImageInt(*right,
432 shadowed_area_bounds.right(),
433 shadowed_area_top,
434 right->width(),
435 shadowed_area_height);
437 // Bottom: left, center, right sides.
438 const gfx::ImageSkia* bottom_left =
439 rb.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER);
440 const gfx::ImageSkia* bottom_center =
441 rb.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER);
442 const gfx::ImageSkia* bottom_right =
443 rb.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER);
445 canvas->DrawImageInt(*bottom_left,
446 shadowed_area_bounds.x() - bottom_left->width(),
447 shadowed_area_bottom);
449 canvas->TileImageInt(*bottom_center,
450 shadowed_area_bounds.x(),
451 shadowed_area_bottom,
452 shadowed_area_bounds.width(),
453 bottom_right->height());
455 canvas->DrawImageInt(*bottom_right,
456 shadowed_area_bounds.right(),
457 shadowed_area_bottom);
458 // Left side.
459 const gfx::ImageSkia* left = rb.GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE);
460 canvas->TileImageInt(*left,
461 shadowed_area_bounds.x() - left->width(),
462 shadowed_area_top,
463 left->width(),
464 shadowed_area_height);
467 SkColor CustomFrameView::GetFrameColor() const {
468 return frame_->IsActive() ? kDefaultColorFrame : kDefaultColorFrameInactive;
471 const gfx::ImageSkia* CustomFrameView::GetFrameImage() const {
472 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
473 frame_->IsActive() ? IDR_FRAME : IDR_FRAME_INACTIVE).ToImageSkia();
476 void CustomFrameView::LayoutWindowControls() {
477 minimum_title_bar_x_ = 0;
478 maximum_title_bar_x_ = width();
480 if (bounds().IsEmpty())
481 return;
483 int caption_y = CaptionButtonY();
484 bool is_maximized = frame_->IsMaximized();
485 // There should always be the same number of non-shadow pixels visible to the
486 // side of the caption buttons. In maximized mode we extend the edge button
487 // to the screen corner to obey Fitts' Law.
488 int extra_width = is_maximized ?
489 (kFrameBorderThickness - kFrameShadowThickness) : 0;
490 int next_button_x = FrameBorderThickness();
492 bool is_restored = !is_maximized && !frame_->IsMinimized();
493 ImageButton* invisible_button = is_restored ? restore_button_
494 : maximize_button_;
495 invisible_button->SetVisible(false);
497 WindowButtonOrderProvider* button_order =
498 WindowButtonOrderProvider::GetInstance();
499 const std::vector<views::FrameButton>& leading_buttons =
500 button_order->leading_buttons();
501 const std::vector<views::FrameButton>& trailing_buttons =
502 button_order->trailing_buttons();
504 ImageButton* button = NULL;
505 for (std::vector<views::FrameButton>::const_iterator it =
506 leading_buttons.begin(); it != leading_buttons.end(); ++it) {
507 button = GetImageButton(*it);
508 if (!button)
509 continue;
510 gfx::Rect target_bounds(gfx::Point(next_button_x, caption_y),
511 button->GetPreferredSize());
512 if (it == leading_buttons.begin())
513 target_bounds.set_width(target_bounds.width() + extra_width);
514 LayoutButton(button, target_bounds);
515 next_button_x += button->width();
516 minimum_title_bar_x_ = std::min(width(), next_button_x);
519 // Trailing buttions are laid out in a RTL fashion
520 next_button_x = width() - FrameBorderThickness();
521 for (std::vector<views::FrameButton>::const_reverse_iterator it =
522 trailing_buttons.rbegin(); it != trailing_buttons.rend(); ++it) {
523 button = GetImageButton(*it);
524 if (!button)
525 continue;
526 gfx::Rect target_bounds(gfx::Point(next_button_x, caption_y),
527 button->GetPreferredSize());
528 if (it == trailing_buttons.rbegin())
529 target_bounds.set_width(target_bounds.width() + extra_width);
530 target_bounds.Offset(-target_bounds.width(), 0);
531 LayoutButton(button, target_bounds);
532 next_button_x = button->x();
533 maximum_title_bar_x_ = std::max(minimum_title_bar_x_, next_button_x);
537 void CustomFrameView::LayoutTitleBar() {
538 DCHECK_GE(maximum_title_bar_x_, 0);
539 // The window title position is calculated based on the icon position, even
540 // when there is no icon.
541 gfx::Rect icon_bounds(IconBounds());
542 bool show_window_icon = window_icon_ != NULL;
543 if (show_window_icon)
544 window_icon_->SetBoundsRect(icon_bounds);
546 if (!frame_->widget_delegate()->ShouldShowWindowTitle())
547 return;
549 // The offset between the window left edge and the title text.
550 int title_x = show_window_icon ? icon_bounds.right() + kTitleIconOffsetX
551 : icon_bounds.x();
552 int title_height = GetTitleFontList().GetHeight();
553 // We bias the title position so that when the difference between the icon and
554 // title heights is odd, the extra pixel of the title is above the vertical
555 // midline rather than below. This compensates for how the icon is already
556 // biased downwards (see IconBounds()) and helps prevent descenders on the
557 // title from overlapping the 3D edge at the bottom of the titlebar.
558 title_bounds_.SetRect(title_x,
559 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2),
560 std::max(0, maximum_title_bar_x_ - kTitleCaptionSpacing -
561 title_x), title_height);
564 void CustomFrameView::LayoutClientView() {
565 if (!ShouldShowTitleBarAndBorder()) {
566 client_view_bounds_ = bounds();
567 return;
570 int top_height = NonClientTopBorderHeight();
571 int border_thickness = NonClientBorderThickness();
572 client_view_bounds_.SetRect(border_thickness, top_height,
573 std::max(0, width() - (2 * border_thickness)),
574 std::max(0, height() - top_height - border_thickness));
577 ImageButton* CustomFrameView::InitWindowCaptionButton(
578 int accessibility_string_id,
579 int normal_image_id,
580 int hot_image_id,
581 int pushed_image_id) {
582 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
583 ImageButton* button = new ImageButton(this);
584 button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id));
585 button->SetImage(CustomButton::STATE_NORMAL,
586 rb.GetImageNamed(normal_image_id).ToImageSkia());
587 button->SetImage(CustomButton::STATE_HOVERED,
588 rb.GetImageNamed(hot_image_id).ToImageSkia());
589 button->SetImage(CustomButton::STATE_PRESSED,
590 rb.GetImageNamed(pushed_image_id).ToImageSkia());
591 AddChildView(button);
592 return button;
595 ImageButton* CustomFrameView::GetImageButton(views::FrameButton frame_button) {
596 ImageButton* button = NULL;
597 switch (frame_button) {
598 case views::FRAME_BUTTON_MINIMIZE: {
599 button = minimize_button_;
600 break;
602 case views::FRAME_BUTTON_MAXIMIZE: {
603 bool is_restored = !frame_->IsMaximized() && !frame_->IsMinimized();
604 button = is_restored ? maximize_button_ : restore_button_;
605 if (!should_show_maximize_button_) {
606 // If we should not show the maximize/restore button, then we return
607 // NULL as we don't want this button to become visible and to be laid
608 // out.
609 button->SetVisible(false);
610 return NULL;
612 break;
614 case views::FRAME_BUTTON_CLOSE: {
615 button = close_button_;
616 break;
619 return button;
622 } // namespace views