OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame/opaque_browser_frame_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" |
6 | 6 |
7 #include "ui/gfx/font.h" | 7 #include "ui/gfx/font.h" |
8 #include "ui/views/controls/button/image_button.h" | 8 #include "ui/views/controls/button/image_button.h" |
9 #include "ui/views/controls/label.h" | 9 #include "ui/views/controls/label.h" |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 const int kNewTabCaptionMaximizedSpacing = 16; | 60 const int kNewTabCaptionMaximizedSpacing = 16; |
61 | 61 |
62 // The top 3 px of the tabstrip is shadow; in maximized mode we push this off | 62 // The top 3 px of the tabstrip is shadow; in maximized mode we push this off |
63 // the top of the screen so the tabs appear flush against the screen edge. | 63 // the top of the screen so the tabs appear flush against the screen edge. |
64 const int kTabstripTopShadowThickness = 3; | 64 const int kTabstripTopShadowThickness = 3; |
65 | 65 |
66 // How far to indent the tabstrip from the left side of the screen when there | 66 // How far to indent the tabstrip from the left side of the screen when there |
67 // is no avatar icon. | 67 // is no avatar icon. |
68 const int kTabStripIndent = -6; | 68 const int kTabStripIndent = -6; |
69 | 69 |
| 70 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 71 // Default extra space between the top of the frame and the top of the window |
| 72 // caption buttons. |
| 73 const int kExtraCaption = 2; |
| 74 |
| 75 // Default extra spacing between individual window caption buttons. |
| 76 const int kCaptionButtonSpacing = 2; |
| 77 #else |
| 78 const int kExtraCaption = 0; |
| 79 const int kCaptionButtonSpacing = 0; |
| 80 #endif |
| 81 |
70 } // namespace | 82 } // namespace |
71 | 83 |
72 /////////////////////////////////////////////////////////////////////////////// | 84 /////////////////////////////////////////////////////////////////////////////// |
73 // OpaqueBrowserFrameView, public: | 85 // OpaqueBrowserFrameView, public: |
74 | 86 |
75 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout( | 87 OpaqueBrowserFrameViewLayout::OpaqueBrowserFrameViewLayout( |
76 OpaqueBrowserFrameViewLayoutDelegate* delegate) | 88 OpaqueBrowserFrameViewLayoutDelegate* delegate) |
77 : delegate_(delegate), | 89 : delegate_(delegate), |
78 leading_button_start_(0), | 90 leading_button_start_(0), |
79 trailing_button_start_(0), | 91 trailing_button_start_(0), |
80 minimum_size_for_buttons_(0), | 92 minimum_size_for_buttons_(0), |
81 has_leading_buttons_(false), | 93 has_leading_buttons_(false), |
82 has_trailing_buttons_(false), | 94 has_trailing_buttons_(false), |
| 95 extra_caption_y_(kExtraCaption), |
| 96 window_caption_spacing_(kCaptionButtonSpacing), |
83 minimize_button_(NULL), | 97 minimize_button_(NULL), |
84 maximize_button_(NULL), | 98 maximize_button_(NULL), |
85 restore_button_(NULL), | 99 restore_button_(NULL), |
86 close_button_(NULL), | 100 close_button_(NULL), |
87 window_icon_(NULL), | 101 window_icon_(NULL), |
88 window_title_(NULL), | 102 window_title_(NULL), |
89 avatar_label_(NULL), | 103 avatar_label_(NULL), |
90 avatar_button_(NULL) { | 104 avatar_button_(NULL) { |
91 trailing_buttons_.push_back(BUTTON_MINIMIZE); | 105 trailing_buttons_.push_back(BUTTON_MINIMIZE); |
92 trailing_buttons_.push_back(BUTTON_MAXIMIZE); | 106 trailing_buttons_.push_back(BUTTON_MAXIMIZE); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 216 |
203 int OpaqueBrowserFrameViewLayout::TitlebarBottomThickness(bool restored) const { | 217 int OpaqueBrowserFrameViewLayout::TitlebarBottomThickness(bool restored) const { |
204 return kTitlebarTopAndBottomEdgeThickness + | 218 return kTitlebarTopAndBottomEdgeThickness + |
205 ((!restored && delegate_->IsMaximized()) ? 0 : | 219 ((!restored && delegate_->IsMaximized()) ? 0 : |
206 views::NonClientFrameView::kClientEdgeThickness); | 220 views::NonClientFrameView::kClientEdgeThickness); |
207 } | 221 } |
208 | 222 |
209 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const { | 223 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const { |
210 // Maximized buttons start at window top so that even if their images aren't | 224 // Maximized buttons start at window top so that even if their images aren't |
211 // drawn flush with the screen edge, they still obey Fitts' Law. | 225 // drawn flush with the screen edge, they still obey Fitts' Law. |
212 return (!restored && delegate_->IsMaximized()) ? | 226 return ((!restored && delegate_->IsMaximized()) ? |
213 FrameBorderThickness(false) : | 227 FrameBorderThickness(false) : |
214 views::NonClientFrameView::kFrameShadowThickness; | 228 views::NonClientFrameView::kFrameShadowThickness) + extra_caption_y_; |
215 } | 229 } |
216 | 230 |
217 gfx::Rect OpaqueBrowserFrameViewLayout::IconBounds() const { | 231 gfx::Rect OpaqueBrowserFrameViewLayout::IconBounds() const { |
218 return window_icon_bounds_; | 232 return window_icon_bounds_; |
219 } | 233 } |
220 | 234 |
221 gfx::Rect OpaqueBrowserFrameViewLayout::CalculateClientAreaBounds( | 235 gfx::Rect OpaqueBrowserFrameViewLayout::CalculateClientAreaBounds( |
222 int width, | 236 int width, |
223 int height) const { | 237 int height) const { |
224 int top_height = NonClientTopBorderHeight(false); | 238 int top_height = NonClientTopBorderHeight(false); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 views::ImageButton::ALIGN_RIGHT : views::ImageButton::ALIGN_LEFT, | 446 views::ImageButton::ALIGN_RIGHT : views::ImageButton::ALIGN_LEFT, |
433 views::ImageButton::ALIGN_BOTTOM); | 447 views::ImageButton::ALIGN_BOTTOM); |
434 | 448 |
435 // There should always be the same number of non-shadow pixels visible to the | 449 // There should always be the same number of non-shadow pixels visible to the |
436 // side of the caption buttons. In maximized mode we extend the rightmost | 450 // side of the caption buttons. In maximized mode we extend the rightmost |
437 // button to the screen corner to obey Fitts' Law. | 451 // button to the screen corner to obey Fitts' Law. |
438 bool is_maximized = delegate_->IsMaximized(); | 452 bool is_maximized = delegate_->IsMaximized(); |
439 | 453 |
440 switch (alignment) { | 454 switch (alignment) { |
441 case ALIGN_LEADING: { | 455 case ALIGN_LEADING: { |
442 // TODO(erg): This works well enough as a basic case, but needs to be | 456 if (has_leading_buttons_) |
443 // expanded for Linux. Inter-button spacing, for example. Also, extending | 457 leading_button_start_ += window_caption_spacing_; |
444 // the leading edge of the first button all the way to the leading edge. | 458 |
| 459 // If we're the first button on the left and maximized, add with to the |
| 460 // right hand side of the screen. |
| 461 int extra_width = (is_maximized && !has_leading_buttons_) ? |
| 462 (kFrameBorderThickness - |
| 463 views::NonClientFrameView::kFrameShadowThickness) : 0; |
| 464 |
445 button->SetBounds( | 465 button->SetBounds( |
446 leading_button_start_, | 466 leading_button_start_ - extra_width, |
447 caption_y, | 467 caption_y, |
448 button_size.width(), | 468 button_size.width() + extra_width, |
449 button_size.height()); | 469 button_size.height()); |
450 | 470 |
451 leading_button_start_ += button_size.width(); | 471 leading_button_start_ += extra_width + button_size.width(); |
452 minimum_size_for_buttons_ += button_size.width(); | 472 minimum_size_for_buttons_ += extra_width + button_size.width(); |
453 has_leading_buttons_ = true; | 473 has_leading_buttons_ = true; |
454 break; | 474 break; |
455 } | 475 } |
456 case ALIGN_TRAILING: { | 476 case ALIGN_TRAILING: { |
| 477 if (has_trailing_buttons_) |
| 478 trailing_button_start_ += window_caption_spacing_; |
| 479 |
457 // If we're the first button on the right and maximized, add with to the | 480 // If we're the first button on the right and maximized, add with to the |
458 // right hand side of the screen. | 481 // right hand side of the screen. |
459 int extra_width = (is_maximized && !has_trailing_buttons_) ? | 482 int extra_width = (is_maximized && !has_trailing_buttons_) ? |
460 (kFrameBorderThickness - | 483 (kFrameBorderThickness - |
461 views::NonClientFrameView::kFrameShadowThickness) : 0; | 484 views::NonClientFrameView::kFrameShadowThickness) : 0; |
462 | 485 |
463 button->SetBounds( | 486 button->SetBounds( |
464 host->width() - trailing_button_start_ - extra_width - | 487 host->width() - trailing_button_start_ - extra_width - |
465 button_size.width(), | 488 button_size.width(), |
466 caption_y, | 489 caption_y, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 589 |
567 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 590 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
568 views::View* view) { | 591 views::View* view) { |
569 SetView(view->id(), view); | 592 SetView(view->id(), view); |
570 } | 593 } |
571 | 594 |
572 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 595 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
573 views::View* view) { | 596 views::View* view) { |
574 SetView(view->id(), NULL); | 597 SetView(view->id(), NULL); |
575 } | 598 } |
OLD | NEW |