OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/window/custom_frame_view.h" | 5 #include "ui/views/window/custom_frame_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #elif defined(OS_WIN) | 26 #elif defined(OS_WIN) |
27 #include "ui/views/widget/native_widget_win.h" | 27 #include "ui/views/widget/native_widget_win.h" |
28 #endif | 28 #endif |
29 | 29 |
30 namespace views { | 30 namespace views { |
31 | 31 |
32 // static | 32 // static |
33 gfx::Font* CustomFrameView::title_font_ = NULL; | 33 gfx::Font* CustomFrameView::title_font_ = NULL; |
34 | 34 |
35 namespace { | 35 namespace { |
| 36 |
36 // The frame border is only visible in restored mode and is hardcoded to 4 px on | 37 // The frame border is only visible in restored mode and is hardcoded to 4 px on |
37 // each side regardless of the system window border size. | 38 // each side regardless of the system window border size. |
38 const int kFrameBorderThickness = 4; | 39 const int kFrameBorderThickness = 4; |
39 // Various edges of the frame border have a 1 px shadow along their edges; in a | 40 // Various edges of the frame border have a 1 px shadow along their edges; in a |
40 // few cases we shift elements based on this amount for visual appeal. | 41 // few cases we shift elements based on this amount for visual appeal. |
41 const int kFrameShadowThickness = 1; | 42 const int kFrameShadowThickness = 1; |
42 // While resize areas on Windows are normally the same size as the window | 43 // While resize areas on Windows are normally the same size as the window |
43 // borders, our top area is shrunk by 1 px to make it easier to move the window | 44 // borders, our top area is shrunk by 1 px to make it easier to move the window |
44 // around with our thinner top grabbable strip. (Incidentally, our side and | 45 // around with our thinner top grabbable strip. (Incidentally, our side and |
45 // bottom resize areas don't match the frame border thickness either -- they | 46 // bottom resize areas don't match the frame border thickness either -- they |
46 // span the whole nonclient area, so there's no "dead zone" for the mouse.) | 47 // span the whole nonclient area, so there's no "dead zone" for the mouse.) |
47 const int kTopResizeAdjust = 1; | 48 const int kTopResizeAdjust = 1; |
48 // In the window corners, the resize areas don't actually expand bigger, but the | 49 // In the window corners, the resize areas don't actually expand bigger, but the |
49 // 16 px at the end of each edge triggers diagonal resizing. | 50 // 16 px at the end of each edge triggers diagonal resizing. |
50 const int kResizeAreaCornerSize = 16; | 51 const int kResizeAreaCornerSize = 16; |
51 // The titlebar never shrinks too short to show the caption button plus some | 52 // The titlebar never shrinks too short to show the caption button plus some |
52 // padding below it. | 53 // padding below it. |
53 const int kCaptionButtonHeightWithPadding = 19; | 54 const int kCaptionButtonHeightWithPadding = 19; |
54 // The titlebar has a 2 px 3D edge along the top and bottom. | 55 // The titlebar has a 2 px 3D edge along the top and bottom. |
55 const int kTitlebarTopAndBottomEdgeThickness = 2; | 56 const int kTitlebarTopAndBottomEdgeThickness = 2; |
56 // The icon is inset 2 px from the left frame border. | 57 // The icon is inset 2 px from the left frame border. |
57 const int kIconLeftSpacing = 2; | 58 const int kIconLeftSpacing = 2; |
58 // The icon never shrinks below 16 px on a side. | 59 // The icon never shrinks below 16 px on a side. |
59 const int kIconMinimumSize = 16; | 60 const int kIconMinimumSize = 16; |
60 // There is a 4 px gap between the icon and the title text. | 61 // There is a 4 px gap between the icon and the title text. |
61 const int kIconTitleSpacing = 4; | 62 const int kIconTitleSpacing = 4; |
62 // There is a 5 px gap between the title text and the caption buttons. | 63 // There is a 5 px gap between the title text and the caption buttons. |
63 const int kTitleCaptionSpacing = 5; | 64 const int kTitleCaptionSpacing = 5; |
64 } | 65 |
| 66 #if defined(USE_AURA) |
| 67 const SkColor kDefaultColorFrame = SkColorSetRGB(109, 109, 109); |
| 68 const SkColor kDefaultColorFrameInactive = SkColorSetRGB(176, 176, 176); |
| 69 #else |
| 70 const SkColor kDefaultColorFrame = SkColorSetRGB(66, 116, 201); |
| 71 const SkColor kDefaultColorFrameInactive = SkColorSetRGB(161, 182, 228); |
| 72 #endif |
| 73 |
| 74 } // namespace |
65 | 75 |
66 /////////////////////////////////////////////////////////////////////////////// | 76 /////////////////////////////////////////////////////////////////////////////// |
67 // CustomFrameView, public: | 77 // CustomFrameView, public: |
68 | 78 |
69 CustomFrameView::CustomFrameView(Widget* frame) | 79 CustomFrameView::CustomFrameView(Widget* frame) |
70 : ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(new ImageButton(this))), | 80 : ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(new ImageButton(this))), |
71 ALLOW_THIS_IN_INITIALIZER_LIST(restore_button_(new ImageButton(this))), | 81 ALLOW_THIS_IN_INITIALIZER_LIST(restore_button_(new ImageButton(this))), |
72 ALLOW_THIS_IN_INITIALIZER_LIST(maximize_button_(new ImageButton(this))), | 82 ALLOW_THIS_IN_INITIALIZER_LIST(maximize_button_(new ImageButton(this))), |
73 ALLOW_THIS_IN_INITIALIZER_LIST(minimize_button_(new ImageButton(this))), | 83 ALLOW_THIS_IN_INITIALIZER_LIST(minimize_button_(new ImageButton(this))), |
74 window_icon_(NULL), | 84 window_icon_(NULL), |
75 should_show_minmax_buttons_(false), | 85 should_show_minmax_buttons_(false), |
76 should_show_client_edge_(false), | 86 should_show_client_edge_(false), |
77 frame_(frame), | 87 frame_(frame), |
78 frame_background_(new FrameBackground()) { | 88 frame_background_(new FrameBackground()) { |
79 InitClass(); | 89 InitClass(); |
80 | 90 |
81 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 91 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
82 | 92 |
83 close_button_->SetAccessibleName( | 93 close_button_->SetAccessibleName( |
84 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); | 94 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE)); |
85 | 95 |
86 // Close button images will be set in LayoutWindowControls(). | 96 // Close button images will be set in LayoutWindowControls(). |
87 AddChildView(close_button_); | 97 AddChildView(close_button_); |
88 | 98 |
89 restore_button_->SetAccessibleName( | 99 restore_button_->SetAccessibleName( |
90 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE)); | 100 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_RESTORE)); |
91 restore_button_->SetImage(CustomButton::BS_NORMAL, | 101 restore_button_->SetImage(CustomButton::BS_NORMAL, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // space above the icon, since the 3D edge (+ client edge, for restored | 317 // space above the icon, since the 3D edge (+ client edge, for restored |
308 // windows) below looks (to the eye) more like additional space than does the | 318 // windows) below looks (to the eye) more like additional space than does the |
309 // 3D edge (or nothing at all, for maximized windows) above; hence the +1. | 319 // 3D edge (or nothing at all, for maximized windows) above; hence the +1. |
310 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - | 320 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - |
311 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; | 321 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; |
312 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); | 322 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); |
313 } | 323 } |
314 | 324 |
315 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { | 325 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { |
316 // Window frame mode. | 326 // Window frame mode. |
317 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 327 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
318 | 328 |
319 frame_background_->set_frame_color(GetFrameColor()); | 329 frame_background_->set_frame_color(GetFrameColor()); |
320 SkBitmap* frame_image = GetFrameBitmap(); | 330 SkBitmap* frame_image = GetFrameBitmap(); |
321 frame_background_->set_theme_bitmap(frame_image); | 331 frame_background_->set_theme_bitmap(frame_image); |
322 frame_background_->set_top_area_height(frame_image->height()); | 332 frame_background_->set_top_area_height(frame_image->height()); |
323 | 333 |
324 #if defined(USE_AURA) | 334 #if defined(USE_AURA) |
325 // TODO(jamescook): Remove this when Aura defaults to its own window frame, | 335 // TODO(jamescook): Remove this when Aura defaults to its own window frame, |
326 // BrowserNonClientFrameViewAura. Until then, use custom square corners to | 336 // BrowserNonClientFrameViewAura. Until then, use custom square corners to |
327 // avoid performance penalties associated with transparent layers. | 337 // avoid performance penalties associated with transparent layers. |
(...skipping 12 matching lines...) Expand all Loading... |
340 frame_background_->SetSideImages( | 350 frame_background_->SetSideImages( |
341 rb.GetBitmapNamed(IDR_WINDOW_LEFT_SIDE), | 351 rb.GetBitmapNamed(IDR_WINDOW_LEFT_SIDE), |
342 rb.GetBitmapNamed(IDR_WINDOW_TOP_CENTER), | 352 rb.GetBitmapNamed(IDR_WINDOW_TOP_CENTER), |
343 rb.GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE), | 353 rb.GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE), |
344 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER)); | 354 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER)); |
345 | 355 |
346 frame_background_->PaintRestored(canvas, this); | 356 frame_background_->PaintRestored(canvas, this); |
347 } | 357 } |
348 | 358 |
349 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { | 359 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { |
350 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 360 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
351 | 361 |
352 SkBitmap* frame_image = GetFrameBitmap(); | 362 SkBitmap* frame_image = GetFrameBitmap(); |
353 frame_background_->set_theme_bitmap(frame_image); | 363 frame_background_->set_theme_bitmap(frame_image); |
354 frame_background_->set_top_area_height(frame_image->height()); | 364 frame_background_->set_top_area_height(frame_image->height()); |
355 | 365 |
356 frame_background_->PaintMaximized(canvas, this); | 366 frame_background_->PaintMaximized(canvas, this); |
357 | 367 |
358 // TODO(jamescook): Migrate this into FrameBackground. | 368 // TODO(jamescook): Migrate this into FrameBackground. |
359 // The bottom of the titlebar actually comes from the top of the Client Edge | 369 // The bottom of the titlebar actually comes from the top of the Client Edge |
360 // graphic, with the actual client edge clipped off the bottom. | 370 // graphic, with the actual client edge clipped off the bottom. |
(...skipping 16 matching lines...) Expand all Loading... |
377 canvas->DrawStringInt(d->GetWindowTitle(), *title_font_, | 387 canvas->DrawStringInt(d->GetWindowTitle(), *title_font_, |
378 SK_ColorWHITE, GetMirroredXForRect(title_bounds_), | 388 SK_ColorWHITE, GetMirroredXForRect(title_bounds_), |
379 title_bounds_.y(), title_bounds_.width(), | 389 title_bounds_.y(), title_bounds_.width(), |
380 title_bounds_.height()); | 390 title_bounds_.height()); |
381 } | 391 } |
382 | 392 |
383 void CustomFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { | 393 void CustomFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { |
384 gfx::Rect client_area_bounds = frame_->client_view()->bounds(); | 394 gfx::Rect client_area_bounds = frame_->client_view()->bounds(); |
385 int client_area_top = client_area_bounds.y(); | 395 int client_area_top = client_area_bounds.y(); |
386 | 396 |
387 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 397 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
388 SkBitmap* top_left = rb.GetBitmapNamed(IDR_APP_TOP_LEFT); | 398 SkBitmap* top_left = rb.GetBitmapNamed(IDR_APP_TOP_LEFT); |
389 SkBitmap* top = rb.GetBitmapNamed(IDR_APP_TOP_CENTER); | 399 SkBitmap* top = rb.GetBitmapNamed(IDR_APP_TOP_CENTER); |
390 SkBitmap* top_right = rb.GetBitmapNamed(IDR_APP_TOP_RIGHT); | 400 SkBitmap* top_right = rb.GetBitmapNamed(IDR_APP_TOP_RIGHT); |
391 SkBitmap* right = rb.GetBitmapNamed(IDR_CONTENT_RIGHT_SIDE); | 401 SkBitmap* right = rb.GetBitmapNamed(IDR_CONTENT_RIGHT_SIDE); |
392 SkBitmap* bottom_right = | 402 SkBitmap* bottom_right = |
393 rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER); | 403 rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER); |
394 SkBitmap* bottom = rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_CENTER); | 404 SkBitmap* bottom = rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_CENTER); |
395 SkBitmap* bottom_left = | 405 SkBitmap* bottom_left = |
396 rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER); | 406 rb.GetBitmapNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER); |
397 SkBitmap* left = rb.GetBitmapNamed(IDR_CONTENT_LEFT_SIDE); | 407 SkBitmap* left = rb.GetBitmapNamed(IDR_CONTENT_LEFT_SIDE); |
(...skipping 21 matching lines...) Expand all Loading... |
419 canvas->DrawBitmapInt(*bottom_left, | 429 canvas->DrawBitmapInt(*bottom_left, |
420 client_area_bounds.x() - bottom_left->width(), client_area_bottom); | 430 client_area_bounds.x() - bottom_left->width(), client_area_bottom); |
421 | 431 |
422 // Left. | 432 // Left. |
423 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), | 433 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), |
424 client_area_top, left->width(), client_area_height); | 434 client_area_top, left->width(), client_area_height); |
425 | 435 |
426 // Draw the toolbar color to fill in the edges. | 436 // Draw the toolbar color to fill in the edges. |
427 canvas->DrawRect(gfx::Rect(client_area_bounds.x() - 1, client_area_top - 1, | 437 canvas->DrawRect(gfx::Rect(client_area_bounds.x() - 1, client_area_top - 1, |
428 client_area_bounds.width() + 1, client_area_bottom - client_area_top + 1), | 438 client_area_bounds.width() + 1, client_area_bottom - client_area_top + 1), |
429 ResourceBundle::toolbar_color); | 439 ui::ResourceBundle::toolbar_color); |
430 } | 440 } |
431 | 441 |
432 SkColor CustomFrameView::GetFrameColor() const { | 442 SkColor CustomFrameView::GetFrameColor() const { |
433 return frame_->IsActive() ? | 443 return frame_->IsActive() ? kDefaultColorFrame : kDefaultColorFrameInactive; |
434 ResourceBundle::frame_color : | |
435 ResourceBundle::frame_color_inactive; | |
436 } | 444 } |
437 | 445 |
438 SkBitmap* CustomFrameView::GetFrameBitmap() const { | 446 SkBitmap* CustomFrameView::GetFrameBitmap() const { |
439 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | 447 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
440 frame_->IsActive() ? IDR_FRAME : IDR_FRAME_INACTIVE); | 448 frame_->IsActive() ? IDR_FRAME : IDR_FRAME_INACTIVE); |
441 } | 449 } |
442 | 450 |
443 void CustomFrameView::LayoutWindowControls() { | 451 void CustomFrameView::LayoutWindowControls() { |
444 close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT, | 452 close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT, |
445 ImageButton::ALIGN_BOTTOM); | 453 ImageButton::ALIGN_BOTTOM); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 title_font_ = new gfx::Font(NativeWidgetWin::GetWindowTitleFont()); | 555 title_font_ = new gfx::Font(NativeWidgetWin::GetWindowTitleFont()); |
548 #elif defined(OS_LINUX) | 556 #elif defined(OS_LINUX) |
549 // TODO(ben): need to resolve what font this is. | 557 // TODO(ben): need to resolve what font this is. |
550 title_font_ = new gfx::Font(); | 558 title_font_ = new gfx::Font(); |
551 #endif | 559 #endif |
552 initialized = true; | 560 initialized = true; |
553 } | 561 } |
554 } | 562 } |
555 | 563 |
556 } // namespace views | 564 } // namespace views |
OLD | NEW |