custom_frame_view.cc revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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. 4 5#include "ui/views/window/custom_frame_view.h" 6 7#include <algorithm> 8 9#include "base/strings/utf_string_conversions.h" 10#include "grit/ui_resources.h" 11#include "grit/ui_strings.h" 12#include "ui/base/hit_test.h" 13#include "ui/base/l10n/l10n_util.h" 14#include "ui/base/resource/resource_bundle.h" 15#include "ui/gfx/canvas.h" 16#include "ui/gfx/font.h" 17#include "ui/gfx/image/image.h" 18#include "ui/gfx/path.h" 19#include "ui/views/color_constants.h" 20#include "ui/views/controls/button/image_button.h" 21#include "ui/views/views_delegate.h" 22#include "ui/views/widget/native_widget_aura.h" 23#include "ui/views/widget/widget.h" 24#include "ui/views/widget/widget_delegate.h" 25#include "ui/views/window/client_view.h" 26#include "ui/views/window/frame_background.h" 27#include "ui/views/window/window_resources.h" 28#include "ui/views/window/window_shape.h" 29 30namespace views { 31 32namespace { 33 34// The frame border is only visible in restored mode and is hardcoded to 4 px on 35// each side regardless of the system window border size. 36const int kFrameBorderThickness = 4; 37// In the window corners, the resize areas don't actually expand bigger, but the 38// 16 px at the end of each edge triggers diagonal resizing. 39const int kResizeAreaCornerSize = 16; 40// The titlebar never shrinks too short to show the caption button plus some 41// padding below it. 42const int kCaptionButtonHeightWithPadding = 19; 43// The titlebar has a 2 px 3D edge along the top and bottom. 44const int kTitlebarTopAndBottomEdgeThickness = 2; 45// The icon is inset 2 px from the left frame border. 46const int kIconLeftSpacing = 2; 47// The icon never shrinks below 16 px on a side. 48const int kIconMinimumSize = 16; 49// The space between the window icon and the title text. 50const int kTitleIconOffsetX = 4; 51// The space between the title text and the caption buttons. 52const int kTitleCaptionSpacing = 5; 53 54#if defined(OS_CHROMEOS) 55// Chrome OS uses a dark gray. 56const SkColor kDefaultColorFrame = SkColorSetRGB(109, 109, 109); 57const SkColor kDefaultColorFrameInactive = SkColorSetRGB(176, 176, 176); 58#else 59// Windows and Linux use a blue. 60const SkColor kDefaultColorFrame = SkColorSetRGB(66, 116, 201); 61const SkColor kDefaultColorFrameInactive = SkColorSetRGB(161, 182, 228); 62#endif 63 64const gfx::FontList& GetTitleFontList() { 65 static const gfx::FontList title_font_list = 66 NativeWidgetAura::GetWindowTitleFontList(); 67 return title_font_list; 68} 69 70} // namespace 71 72/////////////////////////////////////////////////////////////////////////////// 73// CustomFrameView, public: 74 75CustomFrameView::CustomFrameView() 76 : frame_(NULL), 77 window_icon_(NULL), 78 minimize_button_(NULL), 79 maximize_button_(NULL), 80 restore_button_(NULL), 81 close_button_(NULL), 82 should_show_maximize_button_(false), 83 frame_background_(new FrameBackground()) { 84} 85 86CustomFrameView::~CustomFrameView() { 87} 88 89void CustomFrameView::Init(Widget* frame) { 90 frame_ = frame; 91 92 close_button_ = new ImageButton(this); 93 close_button_->SetAccessibleName( 94 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); 95 96 // Close button images will be set in LayoutWindowControls(). 97 AddChildView(close_button_); 98 99 minimize_button_ = InitWindowCaptionButton(IDS_APP_ACCNAME_MINIMIZE, 100 IDR_MINIMIZE, IDR_MINIMIZE_H, IDR_MINIMIZE_P); 101 102 maximize_button_ = InitWindowCaptionButton(IDS_APP_ACCNAME_MAXIMIZE, 103 IDR_MAXIMIZE, IDR_MAXIMIZE_H, IDR_MAXIMIZE_P); 104 105 restore_button_ = InitWindowCaptionButton(IDS_APP_ACCNAME_RESTORE, 106 IDR_RESTORE, IDR_RESTORE_H, IDR_RESTORE_P); 107 108 should_show_maximize_button_ = frame_->widget_delegate()->CanMaximize(); 109 110 if (frame_->widget_delegate()->ShouldShowWindowIcon()) { 111 window_icon_ = new ImageButton(this); 112 AddChildView(window_icon_); 113 } 114} 115 116/////////////////////////////////////////////////////////////////////////////// 117// CustomFrameView, NonClientFrameView implementation: 118 119gfx::Rect CustomFrameView::GetBoundsForClientView() const { 120 return client_view_bounds_; 121} 122 123gfx::Rect CustomFrameView::GetWindowBoundsForClientBounds( 124 const gfx::Rect& client_bounds) const { 125 int top_height = NonClientTopBorderHeight(); 126 int border_thickness = NonClientBorderThickness(); 127 return gfx::Rect(client_bounds.x() - border_thickness, 128 client_bounds.y() - top_height, 129 client_bounds.width() + (2 * border_thickness), 130 client_bounds.height() + top_height + border_thickness); 131} 132 133int CustomFrameView::NonClientHitTest(const gfx::Point& point) { 134 // Sanity check. 135 if (!bounds().Contains(point)) 136 return HTNOWHERE; 137 138 int frame_component = frame_->client_view()->NonClientHitTest(point); 139 140 // See if we're in the sysmenu region. (We check the ClientView first to be 141 // consistent with OpaqueBrowserFrameView; it's not really necessary here.) 142 gfx::Rect sysmenu_rect(IconBounds()); 143 // In maximized mode we extend the rect to the screen corner to take advantage 144 // of Fitts' Law. 145 if (frame_->IsMaximized()) 146 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); 147 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); 148 if (sysmenu_rect.Contains(point)) 149 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; 150 151 if (frame_component != HTNOWHERE) 152 return frame_component; 153 154 // Then see if the point is within any of the window controls. 155 if (close_button_->GetMirroredBounds().Contains(point)) 156 return HTCLOSE; 157 if (restore_button_->GetMirroredBounds().Contains(point)) 158 return HTMAXBUTTON; 159 if (maximize_button_->GetMirroredBounds().Contains(point)) 160 return HTMAXBUTTON; 161 if (minimize_button_->GetMirroredBounds().Contains(point)) 162 return HTMINBUTTON; 163 if (window_icon_ && window_icon_->GetMirroredBounds().Contains(point)) 164 return HTSYSMENU; 165 166 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), 167 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, 168 frame_->widget_delegate()->CanResize()); 169 // Fall back to the caption if no other component matches. 170 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 171} 172 173void CustomFrameView::GetWindowMask(const gfx::Size& size, 174 gfx::Path* window_mask) { 175 DCHECK(window_mask); 176 if (frame_->IsMaximized() || !ShouldShowTitleBarAndBorder()) 177 return; 178 179 GetDefaultWindowMask(size, window_mask); 180} 181 182void CustomFrameView::ResetWindowControls() { 183 restore_button_->SetState(CustomButton::STATE_NORMAL); 184 minimize_button_->SetState(CustomButton::STATE_NORMAL); 185 maximize_button_->SetState(CustomButton::STATE_NORMAL); 186 // The close button isn't affected by this constraint. 187} 188 189void CustomFrameView::UpdateWindowIcon() { 190 if (window_icon_) 191 window_icon_->SchedulePaint(); 192} 193 194void CustomFrameView::UpdateWindowTitle() { 195 SchedulePaintInRect(title_bounds_); 196} 197 198/////////////////////////////////////////////////////////////////////////////// 199// CustomFrameView, View overrides: 200 201void CustomFrameView::OnPaint(gfx::Canvas* canvas) { 202 if (!ShouldShowTitleBarAndBorder()) 203 return; 204 205 if (frame_->IsMaximized()) 206 PaintMaximizedFrameBorder(canvas); 207 else 208 PaintRestoredFrameBorder(canvas); 209 PaintTitleBar(canvas); 210 if (ShouldShowClientEdge()) 211 PaintRestoredClientEdge(canvas); 212} 213 214void CustomFrameView::Layout() { 215 if (ShouldShowTitleBarAndBorder()) { 216 LayoutWindowControls(); 217 LayoutTitleBar(); 218 } 219 220 LayoutClientView(); 221} 222 223gfx::Size CustomFrameView::GetPreferredSize() { 224 return frame_->non_client_view()->GetWindowBoundsForClientBounds( 225 gfx::Rect(frame_->client_view()->GetPreferredSize())).size(); 226} 227 228gfx::Size CustomFrameView::GetMinimumSize() { 229 return frame_->non_client_view()->GetWindowBoundsForClientBounds( 230 gfx::Rect(frame_->client_view()->GetMinimumSize())).size(); 231} 232 233gfx::Size CustomFrameView::GetMaximumSize() { 234 gfx::Size max_size = frame_->client_view()->GetMaximumSize(); 235 gfx::Size converted_size = 236 frame_->non_client_view()->GetWindowBoundsForClientBounds( 237 gfx::Rect(max_size)).size(); 238 return gfx::Size(max_size.width() == 0 ? 0 : converted_size.width(), 239 max_size.height() == 0 ? 0 : converted_size.height()); 240} 241 242/////////////////////////////////////////////////////////////////////////////// 243// CustomFrameView, ButtonListener implementation: 244 245void CustomFrameView::ButtonPressed(Button* sender, const ui::Event& event) { 246 if (sender == close_button_) 247 frame_->Close(); 248 else if (sender == minimize_button_) 249 frame_->Minimize(); 250 else if (sender == maximize_button_) 251 frame_->Maximize(); 252 else if (sender == restore_button_) 253 frame_->Restore(); 254} 255 256/////////////////////////////////////////////////////////////////////////////// 257// CustomFrameView, private: 258 259int CustomFrameView::FrameBorderThickness() const { 260 return frame_->IsMaximized() ? 0 : kFrameBorderThickness; 261} 262 263int CustomFrameView::NonClientBorderThickness() const { 264 // In maximized mode, we don't show a client edge. 265 return FrameBorderThickness() + 266 (ShouldShowClientEdge() ? kClientEdgeThickness : 0); 267} 268 269int CustomFrameView::NonClientTopBorderHeight() const { 270 return std::max(FrameBorderThickness() + IconSize(), 271 CaptionButtonY() + kCaptionButtonHeightWithPadding) + 272 TitlebarBottomThickness(); 273} 274 275int CustomFrameView::CaptionButtonY() const { 276 // Maximized buttons start at window top so that even if their images aren't 277 // drawn flush with the screen edge, they still obey Fitts' Law. 278 return frame_->IsMaximized() ? FrameBorderThickness() : kFrameShadowThickness; 279} 280 281int CustomFrameView::TitlebarBottomThickness() const { 282 return kTitlebarTopAndBottomEdgeThickness + 283 (ShouldShowClientEdge() ? kClientEdgeThickness : 0); 284} 285 286int CustomFrameView::IconSize() const { 287#if defined(OS_WIN) 288 // This metric scales up if either the titlebar height or the titlebar font 289 // size are increased. 290 return GetSystemMetrics(SM_CYSMICON); 291#else 292 return std::max(GetTitleFontList().GetHeight(), kIconMinimumSize); 293#endif 294} 295 296gfx::Rect CustomFrameView::IconBounds() const { 297 int size = IconSize(); 298 int frame_thickness = FrameBorderThickness(); 299 // Our frame border has a different "3D look" than Windows'. Theirs has a 300 // more complex gradient on the top that they push their icon/title below; 301 // then the maximized window cuts this off and the icon/title are centered 302 // in the remaining space. Because the apparent shape of our border is 303 // simpler, using the same positioning makes things look slightly uncentered 304 // with restored windows, so when the window is restored, instead of 305 // calculating the remaining space from below the frame border, we calculate 306 // from below the 3D edge. 307 int unavailable_px_at_top = frame_->IsMaximized() ? 308 frame_thickness : kTitlebarTopAndBottomEdgeThickness; 309 // When the icon is shorter than the minimum space we reserve for the caption 310 // button, we vertically center it. We want to bias rounding to put extra 311 // space above the icon, since the 3D edge (+ client edge, for restored 312 // windows) below looks (to the eye) more like additional space than does the 313 // 3D edge (or nothing at all, for maximized windows) above; hence the +1. 314 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - 315 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; 316 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); 317} 318 319bool CustomFrameView::ShouldShowTitleBarAndBorder() const { 320 if (frame_->IsFullscreen()) 321 return false; 322 323 if (ViewsDelegate::views_delegate) { 324 return !ViewsDelegate::views_delegate->WindowManagerProvidesTitleBar( 325 frame_->IsMaximized()); 326 } 327 328 return true; 329} 330 331bool CustomFrameView::ShouldShowClientEdge() const { 332 return !frame_->IsMaximized() && ShouldShowTitleBarAndBorder(); 333} 334 335void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { 336 frame_background_->set_frame_color(GetFrameColor()); 337 const gfx::ImageSkia* frame_image = GetFrameImage(); 338 frame_background_->set_theme_image(frame_image); 339 frame_background_->set_top_area_height(frame_image->height()); 340 341 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 342 343 frame_background_->SetCornerImages( 344 rb.GetImageNamed(IDR_WINDOW_TOP_LEFT_CORNER).ToImageSkia(), 345 rb.GetImageNamed(IDR_WINDOW_TOP_RIGHT_CORNER).ToImageSkia(), 346 rb.GetImageNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER).ToImageSkia(), 347 rb.GetImageNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER).ToImageSkia()); 348 frame_background_->SetSideImages( 349 rb.GetImageNamed(IDR_WINDOW_LEFT_SIDE).ToImageSkia(), 350 rb.GetImageNamed(IDR_WINDOW_TOP_CENTER).ToImageSkia(), 351 rb.GetImageNamed(IDR_WINDOW_RIGHT_SIDE).ToImageSkia(), 352 rb.GetImageNamed(IDR_WINDOW_BOTTOM_CENTER).ToImageSkia()); 353 354 frame_background_->PaintRestored(canvas, this); 355} 356 357void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { 358 const gfx::ImageSkia* frame_image = GetFrameImage(); 359 frame_background_->set_theme_image(frame_image); 360 frame_background_->set_top_area_height(frame_image->height()); 361 frame_background_->PaintMaximized(canvas, this); 362 363 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 364 365 // TODO(jamescook): Migrate this into FrameBackground. 366 // The bottom of the titlebar actually comes from the top of the Client Edge 367 // graphic, with the actual client edge clipped off the bottom. 368 const gfx::ImageSkia* titlebar_bottom = rb.GetImageNamed( 369 IDR_APP_TOP_CENTER).ToImageSkia(); 370 int edge_height = titlebar_bottom->height() - 371 (ShouldShowClientEdge() ? kClientEdgeThickness : 0); 372 canvas->TileImageInt(*titlebar_bottom, 0, 373 frame_->client_view()->y() - edge_height, width(), edge_height); 374} 375 376void CustomFrameView::PaintTitleBar(gfx::Canvas* canvas) { 377 WidgetDelegate* delegate = frame_->widget_delegate(); 378 379 // It seems like in some conditions we can be asked to paint after the window 380 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The 381 // correct long term fix may be to shut down the RootView in WM_DESTROY. 382 if (!delegate) 383 return; 384 385 gfx::Rect rect = title_bounds_; 386 rect.set_x(GetMirroredXForRect(title_bounds_)); 387 canvas->DrawStringRect(delegate->GetWindowTitle(), GetTitleFontList(), 388 SK_ColorWHITE, rect); 389} 390 391void CustomFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { 392 gfx::Rect client_area_bounds = frame_->client_view()->bounds(); 393 int client_area_top = client_area_bounds.y(); 394 395 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 396 397 // Top: left, center, right sides. 398 const gfx::ImageSkia* top_left = rb.GetImageSkiaNamed(IDR_APP_TOP_LEFT); 399 const gfx::ImageSkia* top_center = rb.GetImageSkiaNamed(IDR_APP_TOP_CENTER); 400 const gfx::ImageSkia* top_right = rb.GetImageSkiaNamed(IDR_APP_TOP_RIGHT); 401 int top_edge_y = client_area_top - top_center->height(); 402 canvas->DrawImageInt(*top_left, 403 client_area_bounds.x() - top_left->width(), 404 top_edge_y); 405 canvas->TileImageInt(*top_center, 406 client_area_bounds.x(), 407 top_edge_y, 408 client_area_bounds.width(), 409 top_center->height()); 410 canvas->DrawImageInt(*top_right, client_area_bounds.right(), top_edge_y); 411 412 // Right side. 413 const gfx::ImageSkia* right = rb.GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE); 414 int client_area_bottom = 415 std::max(client_area_top, client_area_bounds.bottom()); 416 int client_area_height = client_area_bottom - client_area_top; 417 canvas->TileImageInt(*right, 418 client_area_bounds.right(), 419 client_area_top, 420 right->width(), 421 client_area_height); 422 423 // Bottom: left, center, right sides. 424 const gfx::ImageSkia* bottom_left = 425 rb.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER); 426 const gfx::ImageSkia* bottom_center = 427 rb.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER); 428 const gfx::ImageSkia* bottom_right = 429 rb.GetImageSkiaNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER); 430 431 canvas->DrawImageInt(*bottom_left, 432 client_area_bounds.x() - bottom_left->width(), 433 client_area_bottom); 434 435 canvas->TileImageInt(*bottom_center, 436 client_area_bounds.x(), 437 client_area_bottom, 438 client_area_bounds.width(), 439 bottom_right->height()); 440 441 canvas->DrawImageInt(*bottom_right, 442 client_area_bounds.right(), 443 client_area_bottom); 444 // Left side. 445 const gfx::ImageSkia* left = rb.GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE); 446 canvas->TileImageInt(*left, 447 client_area_bounds.x() - left->width(), 448 client_area_top, 449 left->width(), 450 client_area_height); 451 452 // Draw the color to fill in the edges. 453 canvas->FillRect(gfx::Rect(client_area_bounds.x() - 1, 454 client_area_top - 1, 455 client_area_bounds.width() + 1, 456 client_area_bottom - client_area_top + 1), 457 kClientEdgeColor); 458} 459 460SkColor CustomFrameView::GetFrameColor() const { 461 return frame_->IsActive() ? kDefaultColorFrame : kDefaultColorFrameInactive; 462} 463 464const gfx::ImageSkia* CustomFrameView::GetFrameImage() const { 465 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 466 frame_->IsActive() ? IDR_FRAME : IDR_FRAME_INACTIVE).ToImageSkia(); 467} 468 469void CustomFrameView::LayoutWindowControls() { 470 close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT, 471 ImageButton::ALIGN_BOTTOM); 472 int caption_y = CaptionButtonY(); 473 bool is_maximized = frame_->IsMaximized(); 474 // There should always be the same number of non-shadow pixels visible to the 475 // side of the caption buttons. In maximized mode we extend the rightmost 476 // button to the screen corner to obey Fitts' Law. 477 int right_extra_width = is_maximized ? 478 (kFrameBorderThickness - kFrameShadowThickness) : 0; 479 gfx::Size close_button_size = close_button_->GetPreferredSize(); 480 close_button_->SetBounds(width() - FrameBorderThickness() - 481 right_extra_width - close_button_size.width(), caption_y, 482 close_button_size.width() + right_extra_width, 483 close_button_size.height()); 484 485 // When the window is restored, we show a maximized button; otherwise, we show 486 // a restore button. 487 bool is_restored = !is_maximized && !frame_->IsMinimized(); 488 ImageButton* invisible_button = is_restored ? restore_button_ 489 : maximize_button_; 490 invisible_button->SetVisible(false); 491 492 ImageButton* visible_button = is_restored ? maximize_button_ 493 : restore_button_; 494 FramePartImage normal_part, hot_part, pushed_part; 495 int next_button_x; 496 if (should_show_maximize_button_) { 497 visible_button->SetVisible(true); 498 visible_button->SetImageAlignment(ImageButton::ALIGN_LEFT, 499 ImageButton::ALIGN_BOTTOM); 500 gfx::Size visible_button_size = visible_button->GetPreferredSize(); 501 visible_button->SetBounds(close_button_->x() - visible_button_size.width(), 502 caption_y, visible_button_size.width(), 503 visible_button_size.height()); 504 next_button_x = visible_button->x(); 505 } else { 506 visible_button->SetVisible(false); 507 next_button_x = close_button_->x(); 508 } 509 510 minimize_button_->SetVisible(true); 511 minimize_button_->SetImageAlignment(ImageButton::ALIGN_LEFT, 512 ImageButton::ALIGN_BOTTOM); 513 gfx::Size minimize_button_size = minimize_button_->GetPreferredSize(); 514 minimize_button_->SetBounds( 515 next_button_x - minimize_button_size.width(), caption_y, 516 minimize_button_size.width(), 517 minimize_button_size.height()); 518 519 normal_part = IDR_CLOSE; 520 hot_part = IDR_CLOSE_H; 521 pushed_part = IDR_CLOSE_P; 522 523 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 524 525 close_button_->SetImage(CustomButton::STATE_NORMAL, 526 rb.GetImageNamed(normal_part).ToImageSkia()); 527 close_button_->SetImage(CustomButton::STATE_HOVERED, 528 rb.GetImageNamed(hot_part).ToImageSkia()); 529 close_button_->SetImage(CustomButton::STATE_PRESSED, 530 rb.GetImageNamed(pushed_part).ToImageSkia()); 531} 532 533void CustomFrameView::LayoutTitleBar() { 534 // The window title position is calculated based on the icon position, even 535 // when there is no icon. 536 gfx::Rect icon_bounds(IconBounds()); 537 bool show_window_icon = window_icon_ != NULL; 538 if (show_window_icon) 539 window_icon_->SetBoundsRect(icon_bounds); 540 541 // The offset between the window left edge and the title text. 542 int title_x = show_window_icon ? icon_bounds.right() + kTitleIconOffsetX 543 : icon_bounds.x(); 544 int title_height = GetTitleFontList().GetHeight(); 545 // We bias the title position so that when the difference between the icon and 546 // title heights is odd, the extra pixel of the title is above the vertical 547 // midline rather than below. This compensates for how the icon is already 548 // biased downwards (see IconBounds()) and helps prevent descenders on the 549 // title from overlapping the 3D edge at the bottom of the titlebar. 550 title_bounds_.SetRect(title_x, 551 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), 552 std::max(0, minimize_button_->x() - kTitleCaptionSpacing - 553 title_x), title_height); 554} 555 556void CustomFrameView::LayoutClientView() { 557 if (!ShouldShowTitleBarAndBorder()) { 558 client_view_bounds_ = bounds(); 559 return; 560 } 561 562 int top_height = NonClientTopBorderHeight(); 563 int border_thickness = NonClientBorderThickness(); 564 client_view_bounds_.SetRect(border_thickness, top_height, 565 std::max(0, width() - (2 * border_thickness)), 566 std::max(0, height() - top_height - border_thickness)); 567} 568 569ImageButton* CustomFrameView::InitWindowCaptionButton( 570 int accessibility_string_id, 571 int normal_image_id, 572 int hot_image_id, 573 int pushed_image_id) { 574 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 575 ImageButton* button = new ImageButton(this); 576 button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id)); 577 button->SetImage(CustomButton::STATE_NORMAL, 578 rb.GetImageNamed(normal_image_id).ToImageSkia()); 579 button->SetImage(CustomButton::STATE_HOVERED, 580 rb.GetImageNamed(hot_image_id).ToImageSkia()); 581 button->SetImage(CustomButton::STATE_PRESSED, 582 rb.GetImageNamed(pushed_image_id).ToImageSkia()); 583 AddChildView(button); 584 return button; 585} 586 587} // namespace views 588