| 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 "chrome/browser/ui/views/constrained_window_views.h" | 5 #include "chrome/browser/ui/views/constrained_window_views.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 "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
| 31 #include "ui/gfx/font.h" | 31 #include "ui/gfx/font.h" |
| 32 #include "ui/gfx/path.h" | 32 #include "ui/gfx/path.h" |
| 33 #include "ui/gfx/rect.h" | 33 #include "ui/gfx/rect.h" |
| 34 #include "ui/views/controls/button/image_button.h" | 34 #include "ui/views/controls/button/image_button.h" |
| 35 #include "ui/views/focus/focus_manager.h" | 35 #include "ui/views/focus/focus_manager.h" |
| 36 #include "ui/views/views_delegate.h" | 36 #include "ui/views/views_delegate.h" |
| 37 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| 38 #include "ui/views/window/client_view.h" | 38 #include "ui/views/window/client_view.h" |
| 39 #include "ui/views/window/frame_background.h" |
| 39 #include "ui/views/window/non_client_view.h" | 40 #include "ui/views/window/non_client_view.h" |
| 40 #include "ui/views/window/window_resources.h" | 41 #include "ui/views/window/window_resources.h" |
| 41 #include "ui/views/window/window_shape.h" | 42 #include "ui/views/window/window_shape.h" |
| 42 | 43 |
| 43 #if defined(OS_WIN) && !defined(USE_AURA) | 44 #if defined(OS_WIN) && !defined(USE_AURA) |
| 44 #include "ui/views/widget/native_widget_win.h" | 45 #include "ui/views/widget/native_widget_win.h" |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 using base::TimeDelta; | 48 using base::TimeDelta; |
| 48 | 49 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 223 |
| 223 scoped_ptr<views::WindowResources> resources_; | 224 scoped_ptr<views::WindowResources> resources_; |
| 224 | 225 |
| 225 gfx::Rect title_bounds_; | 226 gfx::Rect title_bounds_; |
| 226 | 227 |
| 227 views::ImageButton* close_button_; | 228 views::ImageButton* close_button_; |
| 228 | 229 |
| 229 // The bounds of the ClientView. | 230 // The bounds of the ClientView. |
| 230 gfx::Rect client_view_bounds_; | 231 gfx::Rect client_view_bounds_; |
| 231 | 232 |
| 233 // Background painter for the frame. |
| 234 scoped_ptr<views::FrameBackground> frame_background_; |
| 235 |
| 232 static void InitClass(); | 236 static void InitClass(); |
| 233 | 237 |
| 234 // The font to be used to render the titlebar text. | 238 // The font to be used to render the titlebar text. |
| 235 static const gfx::Font* title_font_; | 239 static const gfx::Font* title_font_; |
| 236 | 240 |
| 237 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameView); | 241 DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowFrameView); |
| 238 }; | 242 }; |
| 239 | 243 |
| 240 const gfx::Font* ConstrainedWindowFrameView::title_font_ = NULL; | 244 const gfx::Font* ConstrainedWindowFrameView::title_font_ = NULL; |
| 241 | 245 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 264 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); | 268 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); |
| 265 } | 269 } |
| 266 | 270 |
| 267 //////////////////////////////////////////////////////////////////////////////// | 271 //////////////////////////////////////////////////////////////////////////////// |
| 268 // ConstrainedWindowFrameView, public: | 272 // ConstrainedWindowFrameView, public: |
| 269 | 273 |
| 270 ConstrainedWindowFrameView::ConstrainedWindowFrameView( | 274 ConstrainedWindowFrameView::ConstrainedWindowFrameView( |
| 271 ConstrainedWindowViews* container) | 275 ConstrainedWindowViews* container) |
| 272 : NonClientFrameView(), | 276 : NonClientFrameView(), |
| 273 container_(container), | 277 container_(container), |
| 274 close_button_(new views::ImageButton(this)) { | 278 close_button_(new views::ImageButton(this)), |
| 279 frame_background_(new views::FrameBackground()) { |
| 275 InitClass(); | 280 InitClass(); |
| 276 InitWindowResources(); | 281 InitWindowResources(); |
| 277 | 282 |
| 278 // Constrained windows always use the custom frame - they just have a | 283 // Constrained windows always use the custom frame - they just have a |
| 279 // different set of bitmaps. | 284 // different set of bitmaps. |
| 280 container->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); | 285 container->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); |
| 281 | 286 |
| 282 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 287 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 283 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 288 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
| 284 rb.GetBitmapNamed(IDR_CLOSE_SA)); | 289 rb.GetBitmapNamed(IDR_CLOSE_SA)); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 // button, we vertically center it. We want to bias rounding to put extra | 423 // button, we vertically center it. We want to bias rounding to put extra |
| 419 // space above the icon, since the 3D edge + client edge below looks (to the | 424 // space above the icon, since the 3D edge + client edge below looks (to the |
| 420 // eye) more like additional space than does the 3D edge above; hence the +1. | 425 // eye) more like additional space than does the 3D edge above; hence the +1. |
| 421 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - | 426 int y = unavailable_px_at_top + (NonClientTopBorderHeight() - |
| 422 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; | 427 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; |
| 423 return gfx::Rect(kFrameBorderThickness + kTitleLeftSpacing, y, size, size); | 428 return gfx::Rect(kFrameBorderThickness + kTitleLeftSpacing, y, size, size); |
| 424 } | 429 } |
| 425 | 430 |
| 426 void ConstrainedWindowFrameView::PaintFrameBorder(gfx::Canvas* canvas) { | 431 void ConstrainedWindowFrameView::PaintFrameBorder(gfx::Canvas* canvas) { |
| 427 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 432 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 433 frame_background_->set_frame_color(ResourceBundle::frame_color); |
| 434 SkBitmap* theme_frame = rb.GetBitmapNamed(IDR_THEME_FRAME); |
| 435 frame_background_->set_theme_bitmap(theme_frame); |
| 436 frame_background_->set_theme_overlay_bitmap(NULL); |
| 437 frame_background_->set_top_area_height(theme_frame->height()); |
| 438 |
| 428 #if defined(USE_AURA) | 439 #if defined(USE_AURA) |
| 429 // TODO(jamescook): Remove this when Aura defaults to its own window frame, | 440 // TODO(jamescook): Remove this when Aura defaults to its own window frame, |
| 430 // BrowserNonClientFrameViewAura. Until then, use custom square corners to | 441 // BrowserNonClientFrameViewAura. Until then, use custom square corners to |
| 431 // avoid performance penalties associated with transparent layers. | 442 // avoid performance penalties associated with transparent layers. |
| 432 SkBitmap* top_left_corner = rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_LEFT); | 443 frame_background_->SetCornerImages( |
| 433 SkBitmap* top_right_corner = rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_RIGHT); | 444 rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_LEFT), |
| 434 SkBitmap* bottom_left_corner = | 445 rb.GetBitmapNamed(IDR_AURA_WINDOW_TOP_RIGHT), |
| 435 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_LEFT); | 446 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_LEFT), |
| 436 SkBitmap* bottom_right_corner = | 447 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_RIGHT)); |
| 437 rb.GetBitmapNamed(IDR_AURA_WINDOW_BOTTOM_RIGHT); | 448 frame_background_->SetSideImages( |
| 438 SkBitmap* top_edge = rb.GetBitmapNamed(IDR_WINDOW_TOP_CENTER); | 449 rb.GetBitmapNamed(IDR_WINDOW_LEFT_SIDE), |
| 439 SkBitmap* right_edge = rb.GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE); | 450 rb.GetBitmapNamed(IDR_WINDOW_TOP_CENTER), |
| 440 SkBitmap* left_edge = rb.GetBitmapNamed(IDR_WINDOW_LEFT_SIDE); | 451 rb.GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE), |
| 441 SkBitmap* bottom_edge = rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER); | 452 rb.GetBitmapNamed(IDR_WINDOW_BOTTOM_CENTER)); |
| 442 #else | 453 #else |
| 443 SkBitmap* top_left_corner = resources_->GetPartBitmap(FRAME_TOP_LEFT_CORNER); | 454 frame_background_->SetCornerImages( |
| 444 SkBitmap* top_right_corner = | 455 resources_->GetPartBitmap(FRAME_TOP_LEFT_CORNER), |
| 445 resources_->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); | 456 resources_->GetPartBitmap(FRAME_TOP_RIGHT_CORNER), |
| 446 SkBitmap* bottom_left_corner = | 457 resources_->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER), |
| 447 resources_->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER); | 458 resources_->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER)); |
| 448 SkBitmap* bottom_right_corner = | 459 frame_background_->SetSideImages( |
| 449 resources_->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER); | 460 resources_->GetPartBitmap(FRAME_LEFT_EDGE), |
| 450 SkBitmap* top_edge = resources_->GetPartBitmap(FRAME_TOP_EDGE); | 461 resources_->GetPartBitmap(FRAME_TOP_EDGE), |
| 451 SkBitmap* right_edge = resources_->GetPartBitmap(FRAME_RIGHT_EDGE); | 462 resources_->GetPartBitmap(FRAME_RIGHT_EDGE), |
| 452 SkBitmap* left_edge = resources_->GetPartBitmap(FRAME_LEFT_EDGE); | 463 resources_->GetPartBitmap(FRAME_BOTTOM_EDGE)); |
| 453 SkBitmap* bottom_edge = resources_->GetPartBitmap(FRAME_BOTTOM_EDGE); | |
| 454 #endif | 464 #endif |
| 455 | 465 |
| 456 SkBitmap* theme_frame = rb.GetBitmapNamed(IDR_THEME_FRAME); | 466 frame_background_->PaintRestored(canvas, this); |
| 457 SkColor frame_color = ResourceBundle::frame_color; | |
| 458 | |
| 459 // Fill with the frame color first so we have a constant background for | |
| 460 // areas not covered by the theme image. | |
| 461 canvas->FillRect(frame_color, | |
| 462 gfx::Rect(0, 0, width(), theme_frame->height())); | |
| 463 | |
| 464 int remaining_height = height() - theme_frame->height(); | |
| 465 if (remaining_height > 0) { | |
| 466 // Now fill down the sides. | |
| 467 canvas->FillRect(frame_color, gfx::Rect(0, theme_frame->height(), | |
| 468 left_edge->width(), | |
| 469 remaining_height)); | |
| 470 canvas->FillRect(frame_color, gfx::Rect(width() - right_edge->width(), | |
| 471 theme_frame->height(), | |
| 472 right_edge->width(), | |
| 473 remaining_height)); | |
| 474 int center_width = width() - left_edge->width() - right_edge->width(); | |
| 475 if (center_width > 0) { | |
| 476 // Now fill the bottom area. | |
| 477 canvas->FillRect(frame_color, | |
| 478 gfx::Rect(left_edge->width(), | |
| 479 height() - bottom_edge->height(), | |
| 480 center_width, bottom_edge->height())); | |
| 481 } | |
| 482 } | |
| 483 | |
| 484 // Draw the theme frame. | |
| 485 canvas->TileImageInt(*theme_frame, 0, 0, width(), theme_frame->height()); | |
| 486 | |
| 487 // Top. | |
| 488 canvas->DrawBitmapInt(*top_left_corner, 0, 0); | |
| 489 canvas->TileImageInt(*top_edge, top_left_corner->width(), 0, | |
| 490 width() - top_right_corner->width(), top_edge->height()); | |
| 491 canvas->DrawBitmapInt(*top_right_corner, | |
| 492 width() - top_right_corner->width(), 0); | |
| 493 | |
| 494 // Right. | |
| 495 canvas->TileImageInt(*right_edge, width() - right_edge->width(), | |
| 496 top_right_corner->height(), right_edge->width(), | |
| 497 height() - top_right_corner->height() - bottom_right_corner->height()); | |
| 498 | |
| 499 // Bottom. | |
| 500 canvas->DrawBitmapInt(*bottom_right_corner, | |
| 501 width() - bottom_right_corner->width(), | |
| 502 height() - bottom_right_corner->height()); | |
| 503 canvas->TileImageInt(*bottom_edge, bottom_left_corner->width(), | |
| 504 height() - bottom_edge->height(), | |
| 505 width() - bottom_left_corner->width() - bottom_right_corner->width(), | |
| 506 bottom_edge->height()); | |
| 507 canvas->DrawBitmapInt(*bottom_left_corner, 0, | |
| 508 height() - bottom_left_corner->height()); | |
| 509 | |
| 510 // Left. | |
| 511 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(), | |
| 512 left_edge->width(), | |
| 513 height() - top_left_corner->height() - bottom_left_corner->height()); | |
| 514 } | 467 } |
| 515 | 468 |
| 516 void ConstrainedWindowFrameView::PaintTitleBar(gfx::Canvas* canvas) { | 469 void ConstrainedWindowFrameView::PaintTitleBar(gfx::Canvas* canvas) { |
| 517 canvas->DrawStringInt( | 470 canvas->DrawStringInt( |
| 518 container_->widget_delegate()->GetWindowTitle(), | 471 container_->widget_delegate()->GetWindowTitle(), |
| 519 *title_font_, GetTitleColor(), GetMirroredXForRect(title_bounds_), | 472 *title_font_, GetTitleColor(), GetMirroredXForRect(title_bounds_), |
| 520 title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); | 473 title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); |
| 521 } | 474 } |
| 522 | 475 |
| 523 void ConstrainedWindowFrameView::PaintClientEdge(gfx::Canvas* canvas) { | 476 void ConstrainedWindowFrameView::PaintClientEdge(gfx::Canvas* canvas) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 } | 612 } |
| 660 | 613 |
| 661 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { | 614 void ConstrainedWindowViews::OnNativeConstrainedWindowMouseActivate() { |
| 662 Activate(); | 615 Activate(); |
| 663 } | 616 } |
| 664 | 617 |
| 665 views::internal::NativeWidgetDelegate* | 618 views::internal::NativeWidgetDelegate* |
| 666 ConstrainedWindowViews::AsNativeWidgetDelegate() { | 619 ConstrainedWindowViews::AsNativeWidgetDelegate() { |
| 667 return this; | 620 return this; |
| 668 } | 621 } |
| OLD | NEW |