| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/constrained_window_impl.h" | 5 #include "chrome/browser/views/constrained_window_impl.h" |
| 6 | 6 |
| 7 #include "app/gfx/chrome_canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/gfx/chrome_font.h" | 8 #include "app/gfx/font.h" |
| 9 #include "app/gfx/path.h" | 9 #include "app/gfx/path.h" |
| 10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
| 11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
| 13 #include "app/win_util.h" | 13 #include "app/win_util.h" |
| 14 #include "base/gfx/rect.h" | 14 #include "base/gfx/rect.h" |
| 15 #include "chrome/app/chrome_dll_resource.h" | 15 #include "chrome/app/chrome_dll_resource.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 18 #include "chrome/browser/tab_contents/tab_contents.h" | 18 #include "chrome/browser/tab_contents/tab_contents.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 virtual bool AlwaysUseCustomFrame() const; | 170 virtual bool AlwaysUseCustomFrame() const; |
| 171 virtual gfx::Rect GetWindowBoundsForClientBounds( | 171 virtual gfx::Rect GetWindowBoundsForClientBounds( |
| 172 const gfx::Rect& client_bounds) const; | 172 const gfx::Rect& client_bounds) const; |
| 173 virtual gfx::Point GetSystemMenuPoint() const; | 173 virtual gfx::Point GetSystemMenuPoint() const; |
| 174 virtual int NonClientHitTest(const gfx::Point& point); | 174 virtual int NonClientHitTest(const gfx::Point& point); |
| 175 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask); | 175 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask); |
| 176 virtual void EnableClose(bool enable); | 176 virtual void EnableClose(bool enable); |
| 177 virtual void ResetWindowControls() { } | 177 virtual void ResetWindowControls() { } |
| 178 | 178 |
| 179 // Overridden from views::View: | 179 // Overridden from views::View: |
| 180 virtual void Paint(ChromeCanvas* canvas); | 180 virtual void Paint(gfx::Canvas* canvas); |
| 181 virtual void Layout(); | 181 virtual void Layout(); |
| 182 virtual void ThemeChanged(); | 182 virtual void ThemeChanged(); |
| 183 | 183 |
| 184 // Overridden from views::ButtonListener: | 184 // Overridden from views::ButtonListener: |
| 185 virtual void ButtonPressed(views::Button* sender); | 185 virtual void ButtonPressed(views::Button* sender); |
| 186 | 186 |
| 187 private: | 187 private: |
| 188 // Returns the thickness of the border that makes up the window frame edges. | 188 // Returns the thickness of the border that makes up the window frame edges. |
| 189 // This does not include any client edge. | 189 // This does not include any client edge. |
| 190 int FrameBorderThickness() const; | 190 int FrameBorderThickness() const; |
| 191 | 191 |
| 192 // Returns the thickness of the entire nonclient left, right, and bottom | 192 // Returns the thickness of the entire nonclient left, right, and bottom |
| 193 // borders, including both the window frame and any client edge. | 193 // borders, including both the window frame and any client edge. |
| 194 int NonClientBorderThickness() const; | 194 int NonClientBorderThickness() const; |
| 195 | 195 |
| 196 // Returns the height of the entire nonclient top border, including the window | 196 // Returns the height of the entire nonclient top border, including the window |
| 197 // frame, any title area, and any connected client edge. | 197 // frame, any title area, and any connected client edge. |
| 198 int NonClientTopBorderHeight() const; | 198 int NonClientTopBorderHeight() const; |
| 199 | 199 |
| 200 // Calculates multiple values related to title layout. Returns the height of | 200 // Calculates multiple values related to title layout. Returns the height of |
| 201 // the entire titlebar including any connected client edge. | 201 // the entire titlebar including any connected client edge. |
| 202 int TitleCoordinates(int* title_top_spacing, | 202 int TitleCoordinates(int* title_top_spacing, |
| 203 int* title_thickness) const; | 203 int* title_thickness) const; |
| 204 | 204 |
| 205 // Paints different parts of the window to the incoming canvas. | 205 // Paints different parts of the window to the incoming canvas. |
| 206 void PaintFrameBorder(ChromeCanvas* canvas); | 206 void PaintFrameBorder(gfx::Canvas* canvas); |
| 207 void PaintTitleBar(ChromeCanvas* canvas); | 207 void PaintTitleBar(gfx::Canvas* canvas); |
| 208 void PaintClientEdge(ChromeCanvas* canvas); | 208 void PaintClientEdge(gfx::Canvas* canvas); |
| 209 | 209 |
| 210 // Layout various sub-components of this view. | 210 // Layout various sub-components of this view. |
| 211 void LayoutWindowControls(); | 211 void LayoutWindowControls(); |
| 212 void LayoutTitleBar(); | 212 void LayoutTitleBar(); |
| 213 void LayoutClientView(); | 213 void LayoutClientView(); |
| 214 | 214 |
| 215 // Returns the bounds of the client area for the specified view size. | 215 // Returns the bounds of the client area for the specified view size. |
| 216 gfx::Rect CalculateClientAreaBounds(int width, int height) const; | 216 gfx::Rect CalculateClientAreaBounds(int width, int height) const; |
| 217 | 217 |
| 218 SkColor GetTitleColor() const { | 218 SkColor GetTitleColor() const { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 window_mask->close(); | 374 window_mask->close(); |
| 375 } | 375 } |
| 376 | 376 |
| 377 void ConstrainedWindowFrameView::EnableClose(bool enable) { | 377 void ConstrainedWindowFrameView::EnableClose(bool enable) { |
| 378 close_button_->SetEnabled(enable); | 378 close_button_->SetEnabled(enable); |
| 379 } | 379 } |
| 380 | 380 |
| 381 //////////////////////////////////////////////////////////////////////////////// | 381 //////////////////////////////////////////////////////////////////////////////// |
| 382 // ConstrainedWindowFrameView, views::View implementation: | 382 // ConstrainedWindowFrameView, views::View implementation: |
| 383 | 383 |
| 384 void ConstrainedWindowFrameView::Paint(ChromeCanvas* canvas) { | 384 void ConstrainedWindowFrameView::Paint(gfx::Canvas* canvas) { |
| 385 PaintFrameBorder(canvas); | 385 PaintFrameBorder(canvas); |
| 386 PaintTitleBar(canvas); | 386 PaintTitleBar(canvas); |
| 387 PaintClientEdge(canvas); | 387 PaintClientEdge(canvas); |
| 388 } | 388 } |
| 389 | 389 |
| 390 void ConstrainedWindowFrameView::Layout() { | 390 void ConstrainedWindowFrameView::Layout() { |
| 391 LayoutWindowControls(); | 391 LayoutWindowControls(); |
| 392 LayoutTitleBar(); | 392 LayoutTitleBar(); |
| 393 LayoutClientView(); | 393 LayoutClientView(); |
| 394 } | 394 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 int min_titlebar_height = kTitlebarMinimumHeight + frame_thickness; | 428 int min_titlebar_height = kTitlebarMinimumHeight + frame_thickness; |
| 429 *title_top_spacing = frame_thickness + kTitleTopSpacing; | 429 *title_top_spacing = frame_thickness + kTitleTopSpacing; |
| 430 // The bottom spacing should be the same apparent height as the top spacing, | 430 // The bottom spacing should be the same apparent height as the top spacing, |
| 431 // plus have the client edge tacked on. | 431 // plus have the client edge tacked on. |
| 432 int title_bottom_spacing = *title_top_spacing + kClientEdgeThickness; | 432 int title_bottom_spacing = *title_top_spacing + kClientEdgeThickness; |
| 433 *title_thickness = std::max(title_font_->height(), | 433 *title_thickness = std::max(title_font_->height(), |
| 434 min_titlebar_height - *title_top_spacing - title_bottom_spacing); | 434 min_titlebar_height - *title_top_spacing - title_bottom_spacing); |
| 435 return *title_top_spacing + *title_thickness + title_bottom_spacing; | 435 return *title_top_spacing + *title_thickness + title_bottom_spacing; |
| 436 } | 436 } |
| 437 | 437 |
| 438 void ConstrainedWindowFrameView::PaintFrameBorder(ChromeCanvas* canvas) { | 438 void ConstrainedWindowFrameView::PaintFrameBorder(gfx::Canvas* canvas) { |
| 439 SkBitmap* top_left_corner = resources_->GetPartBitmap(FRAME_TOP_LEFT_CORNER); | 439 SkBitmap* top_left_corner = resources_->GetPartBitmap(FRAME_TOP_LEFT_CORNER); |
| 440 SkBitmap* top_right_corner = | 440 SkBitmap* top_right_corner = |
| 441 resources_->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); | 441 resources_->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); |
| 442 SkBitmap* top_edge = resources_->GetPartBitmap(FRAME_TOP_EDGE); | 442 SkBitmap* top_edge = resources_->GetPartBitmap(FRAME_TOP_EDGE); |
| 443 SkBitmap* right_edge = resources_->GetPartBitmap(FRAME_RIGHT_EDGE); | 443 SkBitmap* right_edge = resources_->GetPartBitmap(FRAME_RIGHT_EDGE); |
| 444 SkBitmap* left_edge = resources_->GetPartBitmap(FRAME_LEFT_EDGE); | 444 SkBitmap* left_edge = resources_->GetPartBitmap(FRAME_LEFT_EDGE); |
| 445 SkBitmap* bottom_left_corner = | 445 SkBitmap* bottom_left_corner = |
| 446 resources_->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER); | 446 resources_->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER); |
| 447 SkBitmap* bottom_right_corner = | 447 SkBitmap* bottom_right_corner = |
| 448 resources_->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER); | 448 resources_->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 bottom_edge->height()); | 495 bottom_edge->height()); |
| 496 canvas->DrawBitmapInt(*bottom_left_corner, 0, | 496 canvas->DrawBitmapInt(*bottom_left_corner, 0, |
| 497 height() - bottom_left_corner->height()); | 497 height() - bottom_left_corner->height()); |
| 498 | 498 |
| 499 // Left. | 499 // Left. |
| 500 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(), | 500 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(), |
| 501 left_edge->width(), | 501 left_edge->width(), |
| 502 height() - top_left_corner->height() - bottom_left_corner->height()); | 502 height() - top_left_corner->height() - bottom_left_corner->height()); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void ConstrainedWindowFrameView::PaintTitleBar(ChromeCanvas* canvas) { | 505 void ConstrainedWindowFrameView::PaintTitleBar(gfx::Canvas* canvas) { |
| 506 canvas->DrawStringInt(container_->GetWindowTitle(), *title_font_, | 506 canvas->DrawStringInt(container_->GetWindowTitle(), *title_font_, |
| 507 GetTitleColor(), MirroredLeftPointForRect(title_bounds_), | 507 GetTitleColor(), MirroredLeftPointForRect(title_bounds_), |
| 508 title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); | 508 title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void ConstrainedWindowFrameView::PaintClientEdge(ChromeCanvas* canvas) { | 511 void ConstrainedWindowFrameView::PaintClientEdge(gfx::Canvas* canvas) { |
| 512 gfx::Rect client_edge_bounds(CalculateClientAreaBounds(width(), height())); | 512 gfx::Rect client_edge_bounds(CalculateClientAreaBounds(width(), height())); |
| 513 client_edge_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness); | 513 client_edge_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness); |
| 514 gfx::Rect frame_shadow_bounds(client_edge_bounds); | 514 gfx::Rect frame_shadow_bounds(client_edge_bounds); |
| 515 frame_shadow_bounds.Inset(-kFrameShadowThickness, -kFrameShadowThickness); | 515 frame_shadow_bounds.Inset(-kFrameShadowThickness, -kFrameShadowThickness); |
| 516 | 516 |
| 517 canvas->FillRectInt(kContentsBorderShadow, frame_shadow_bounds.x(), | 517 canvas->FillRectInt(kContentsBorderShadow, frame_shadow_bounds.x(), |
| 518 frame_shadow_bounds.y(), frame_shadow_bounds.width(), | 518 frame_shadow_bounds.y(), frame_shadow_bounds.width(), |
| 519 frame_shadow_bounds.height()); | 519 frame_shadow_bounds.height()); |
| 520 | 520 |
| 521 canvas->FillRectInt(ResourceBundle::toolbar_color, client_edge_bounds.x(), | 521 canvas->FillRectInt(ResourceBundle::toolbar_color, client_edge_bounds.x(), |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( | 735 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( |
| 736 TabContents* parent, | 736 TabContents* parent, |
| 737 const gfx::Rect& initial_bounds, | 737 const gfx::Rect& initial_bounds, |
| 738 views::View* contents_view, | 738 views::View* contents_view, |
| 739 views::WindowDelegate* window_delegate) { | 739 views::WindowDelegate* window_delegate) { |
| 740 ConstrainedWindowImpl* window = new ConstrainedWindowImpl(parent, | 740 ConstrainedWindowImpl* window = new ConstrainedWindowImpl(parent, |
| 741 window_delegate); | 741 window_delegate); |
| 742 window->InitAsDialog(initial_bounds); | 742 window->InitAsDialog(initial_bounds); |
| 743 return window; | 743 return window; |
| 744 } | 744 } |
| OLD | NEW |