OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_frame_simple.h" | 5 #include "chrome/browser/ui/views/constrained_window_frame_simple.h" |
6 | 6 |
7 #include "chrome/browser/ui/constrained_window_constants.h" | 7 #include "chrome/browser/ui/constrained_window_constants.h" |
8 #include "chrome/browser/ui/constrained_window.h" | 8 #include "chrome/browser/ui/constrained_window.h" |
9 #include "chrome/browser/ui/views/constrained_window_views.h" | 9 #include "chrome/browser/ui/views/constrained_window_views.h" |
10 #include "grit/chromium_strings.h" | 10 #include "grit/chromium_strings.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/views/controls/button/image_button.h" | 21 #include "ui/views/controls/button/image_button.h" |
22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
23 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
24 #include "ui/views/layout/layout_constants.h" | 24 #include "ui/views/layout/layout_constants.h" |
25 #include "ui/views/layout/layout_manager.h" | 25 #include "ui/views/layout/layout_manager.h" |
26 #include "ui/views/widget/widget_delegate.h" | 26 #include "ui/views/widget/widget_delegate.h" |
27 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
28 | 28 |
29 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple( | 29 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple( |
30 ConstrainedWindowViews* container, | 30 ConstrainedWindowViews* container, |
31 ConstrainedWindowViews::ChromeStyleClientInsets client_insets) | 31 ConstrainedWindowViews::ChromeStyleFrameLayout frame_layout) |
32 : container_(container), | 32 : container_(container), |
33 client_insets_(client_insets), | 33 frame_layout_(frame_layout), |
34 title_label_(NULL), | 34 title_label_(NULL), |
35 close_button_(NULL), | 35 close_button_(NULL), |
36 bottom_margin_(0) { | 36 bottom_margin_(0) { |
37 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); | 37 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); |
38 | 38 |
39 #if defined(OS_WIN) && !defined(USE_AURA) | 39 #if defined(OS_WIN) && !defined(USE_AURA) |
40 const SkColor stroke_color = SkColorSetRGB(0xaa, 0xaa, 0xaa); | 40 const SkColor stroke_color = SkColorSetRGB(0xaa, 0xaa, 0xaa); |
41 set_border(views::Border::CreateSolidBorder(1, stroke_color)); | 41 set_border(views::Border::CreateSolidBorder(1, stroke_color)); |
42 #else | 42 #else |
43 set_border(views::Border::CreateEmptyBorder(0, 0, 0, 0)); | 43 set_border(views::Border::CreateEmptyBorder(0, 0, 0, 0)); |
44 #endif | 44 #endif |
45 | 45 |
46 // The NO_INSETS consumers draw atop the frame and do not get the close button | 46 // The FRAME_LAYOUT_NONE consumers draw atop the frame and do not get the |
47 // and title label below. | 47 // close button and title label below. |
48 if (client_insets_ == ConstrainedWindowViews::NO_INSETS) | 48 if (frame_layout_ == ConstrainedWindowViews::FRAME_LAYOUT_NONE) |
49 return; | 49 return; |
50 | 50 |
51 gfx::Insets border_insets = border()->GetInsets(); | 51 gfx::Insets border_insets = border()->GetInsets(); |
52 | 52 |
53 views::GridLayout* layout = new views::GridLayout(this); | 53 views::GridLayout* layout = new views::GridLayout(this); |
54 const int kHeaderTopPadding = std::min( | 54 const int kHeaderTopPadding = std::min( |
55 ConstrainedWindowConstants::kCloseButtonPadding, | 55 ConstrainedWindowConstants::kCloseButtonPadding, |
56 ConstrainedWindowConstants::kTitleTopPadding); | 56 ConstrainedWindowConstants::kTitleTopPadding); |
57 layout->SetInsets(border_insets.top() + kHeaderTopPadding, | 57 layout->SetInsets(border_insets.top() + kHeaderTopPadding, |
58 border_insets.left() + | 58 border_insets.left() + |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 // - The client insets are the distance from the window border to the client | 104 // - The client insets are the distance from the window border to the client |
105 // view. | 105 // view. |
106 // - The header insets are the distance from the window border to the header | 106 // - The header insets are the distance from the window border to the header |
107 // elements. | 107 // elements. |
108 gfx::Insets ConstrainedWindowFrameSimple::GetClientInsets() const { | 108 gfx::Insets ConstrainedWindowFrameSimple::GetClientInsets() const { |
109 gfx::Insets insets; | 109 gfx::Insets insets; |
110 | 110 |
111 if (border()) | 111 if (border()) |
112 insets += border()->GetInsets(); | 112 insets += border()->GetInsets(); |
113 | 113 |
114 if (client_insets_ == ConstrainedWindowViews::DEFAULT_INSETS) { | 114 if (frame_layout_ == ConstrainedWindowViews::FRAME_LAYOUT_FULL || |
| 115 frame_layout_ == ConstrainedWindowViews::FRAME_LAYOUT_HEADER_ONLY) { |
115 const int kHeaderTopPadding = std::min( | 116 const int kHeaderTopPadding = std::min( |
116 ConstrainedWindowConstants::kCloseButtonPadding, | 117 ConstrainedWindowConstants::kCloseButtonPadding, |
117 ConstrainedWindowConstants::kTitleTopPadding); | 118 ConstrainedWindowConstants::kTitleTopPadding); |
118 const int kTitleBuiltinBottomPadding = 4; | 119 const int kTitleBuiltinBottomPadding = 4; |
| 120 const int kClientHorizontalPadding = |
| 121 frame_layout_ == ConstrainedWindowViews::FRAME_LAYOUT_FULL ? |
| 122 ConstrainedWindowConstants::kHorizontalPadding : 0; |
| 123 const int kClientBottomPadding = |
| 124 frame_layout_ == ConstrainedWindowViews::FRAME_LAYOUT_FULL ? |
| 125 ConstrainedWindowConstants::kClientBottomPadding - bottom_margin_ : 0; |
119 insets += gfx::Insets( | 126 insets += gfx::Insets( |
120 ConstrainedWindowConstants::kClientTopPadding + kHeaderTopPadding + | 127 ConstrainedWindowConstants::kClientTopPadding + kHeaderTopPadding + |
121 std::max(close_button_->GetPreferredSize().height(), | 128 std::max(close_button_->GetPreferredSize().height(), |
122 title_label_->GetPreferredSize().height()) - | 129 title_label_->GetPreferredSize().height()) - |
123 kTitleBuiltinBottomPadding, | 130 kTitleBuiltinBottomPadding, |
124 ConstrainedWindowConstants::kHorizontalPadding, | 131 kClientHorizontalPadding, |
125 ConstrainedWindowConstants::kClientBottomPadding - bottom_margin_, | 132 kClientBottomPadding, |
126 ConstrainedWindowConstants::kHorizontalPadding); | 133 kClientHorizontalPadding); |
127 } | 134 } |
128 | 135 |
129 return insets; | 136 return insets; |
130 } | 137 } |
131 | 138 |
132 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const { | 139 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const { |
133 gfx::Rect contents_bounds(GetLocalBounds()); | 140 gfx::Rect contents_bounds(GetLocalBounds()); |
134 gfx::Insets insets = GetClientInsets(); | 141 gfx::Insets insets = GetClientInsets(); |
135 contents_bounds.Inset(insets); | 142 contents_bounds.Inset(insets); |
136 return contents_bounds; | 143 return contents_bounds; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return GetWindowBoundsForClientBounds( | 196 return GetWindowBoundsForClientBounds( |
190 gfx::Rect(container_->client_view()->GetPreferredSize())).size(); | 197 gfx::Rect(container_->client_view()->GetPreferredSize())).size(); |
191 } | 198 } |
192 | 199 |
193 void ConstrainedWindowFrameSimple::ButtonPressed(views::Button* sender, | 200 void ConstrainedWindowFrameSimple::ButtonPressed(views::Button* sender, |
194 const ui::Event& event) { | 201 const ui::Event& event) { |
195 DCHECK(close_button_); | 202 DCHECK(close_button_); |
196 if (sender == close_button_) | 203 if (sender == close_button_) |
197 sender->GetWidget()->Close(); | 204 sender->GetWidget()->Close(); |
198 } | 205 } |
OLD | NEW |