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