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/chromeos/frame/bubble_frame_view.h" | 5 #include "chrome/browser/chromeos/frame/bubble_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 "chrome/browser/chromeos/frame/bubble_window.h" | 10 #include "chrome/browser/chromeos/frame/bubble_window.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 gfx::Path* window_mask) { | 133 gfx::Path* window_mask) { |
134 } | 134 } |
135 | 135 |
136 void BubbleFrameView::ResetWindowControls() { | 136 void BubbleFrameView::ResetWindowControls() { |
137 } | 137 } |
138 | 138 |
139 void BubbleFrameView::UpdateWindowIcon() { | 139 void BubbleFrameView::UpdateWindowIcon() { |
140 } | 140 } |
141 | 141 |
142 gfx::Insets BubbleFrameView::GetInsets() const { | 142 gfx::Insets BubbleFrameView::GetInsets() const { |
143 return (style_ & STYLE_FLUSH) ? | 143 return (style_ & STYLE_FLUSH || style_ & STYLE_FLUSH_CONTENT) ? |
144 gfx::Insets() : | 144 gfx::Insets() : |
145 gfx::Insets(kTitleTopPadding, | 145 gfx::Insets(kTitleTopPadding, |
146 kHorizontalPadding, | 146 kHorizontalPadding, |
147 0, | 147 0, |
148 kHorizontalPadding); | 148 kHorizontalPadding); |
149 } | 149 } |
150 | 150 |
151 gfx::Size BubbleFrameView::GetPreferredSize() { | 151 gfx::Size BubbleFrameView::GetPreferredSize() { |
152 gfx::Size pref = frame_->client_view()->GetPreferredSize(); | 152 gfx::Size pref = frame_->client_view()->GetPreferredSize(); |
153 gfx::Rect bounds(0, 0, pref.width(), pref.height()); | 153 gfx::Rect bounds(0, 0, pref.width(), pref.height()); |
154 return frame_->non_client_view()->GetWindowBoundsForClientBounds( | 154 return frame_->non_client_view()->GetWindowBoundsForClientBounds( |
155 bounds).size(); | 155 bounds).size(); |
156 } | 156 } |
157 | 157 |
158 void BubbleFrameView::Layout() { | 158 void BubbleFrameView::Layout() { |
159 gfx::Insets insets = GetInsets(); | 159 gfx::Insets insets = GetInsets(); |
160 | 160 |
161 gfx::Size title_size; | 161 gfx::Size title_size; |
162 if (title_) | 162 if (title_) |
163 title_size = title_->GetPreferredSize(); | 163 title_size = title_->GetPreferredSize(); |
164 gfx::Size close_button_size; | 164 gfx::Size close_button_size; |
165 if (close_button_) | 165 if (close_button_) |
166 close_button_size = close_button_->GetPreferredSize(); | 166 close_button_size = close_button_->GetPreferredSize(); |
167 gfx::Size throbber_size; | 167 gfx::Size throbber_size; |
168 if (throbber_) | 168 if (throbber_) |
169 throbber_size = throbber_->GetPreferredSize(); | 169 throbber_size = throbber_->GetPreferredSize(); |
170 | 170 |
| 171 // Need to center elements which are shorter. |
| 172 int max_height = std::max(title_size.height(), |
| 173 std::max(close_button_size.height(), |
| 174 throbber_size.height())); |
| 175 |
| 176 gfx::Insets title_insets = gfx::Insets(); |
| 177 // Need to insert title padding for STYLE_FLUSH_CONTENT. |
| 178 if (style_ & STYLE_FLUSH_CONTENT) |
| 179 title_insets = gfx::Insets(kTitleTopPadding, |
| 180 kHorizontalPadding, |
| 181 0, |
| 182 kHorizontalPadding); |
| 183 |
171 if (title_) { | 184 if (title_) { |
172 title_->SetBounds( | 185 title_->SetBounds( |
173 insets.left(), insets.top(), | 186 insets.left() + title_insets.left(), |
174 std::max(0, width() - insets.width() - close_button_size.width()), | 187 insets.top() + title_insets.top() + |
| 188 (max_height - title_size.height())/2, // Center. |
| 189 std::max(0, width() - insets.width() - title_insets.width() - |
| 190 close_button_size.width()), |
175 title_size.height()); | 191 title_size.height()); |
176 } | 192 } |
177 | 193 |
178 if (close_button_) { | 194 if (close_button_) { |
179 close_button_->SetBounds( | 195 close_button_->SetBounds( |
180 width() - insets.right() - close_button_size.width(), insets.top(), | 196 width() - insets.right() - title_insets.right() - |
181 close_button_size.width(), close_button_size.height()); | 197 close_button_size.width(), |
| 198 insets.top() + title_insets.top() + |
| 199 (max_height - close_button_size.height())/2, |
| 200 close_button_size.width(), |
| 201 close_button_size.height()); |
182 } | 202 } |
183 | 203 |
184 if (throbber_) { | 204 if (throbber_) { |
185 throbber_->SetBounds( | 205 throbber_->SetBounds( |
186 insets.left(), insets.top(), | 206 insets.left() + title_insets.left(), |
| 207 insets.top() + title_insets.top() + |
| 208 (max_height - throbber_size.height())/2, |
187 std::min(throbber_size.width(), width()), | 209 std::min(throbber_size.width(), width()), |
188 throbber_size.height()); | 210 throbber_size.height()); |
189 } | 211 } |
190 | 212 |
191 int top_height = insets.top(); | 213 int top_height = insets.top() + title_insets.top(); |
192 if (title_size.height() > 0 || | 214 if (title_size.height() > 0 || |
193 close_button_size.height() > 0 || | 215 close_button_size.height() > 0 || |
194 throbber_size.height() > 0) { | 216 throbber_size.height() > 0) { |
195 top_height += kTitleContentPadding + std::max( | 217 top_height += kTitleContentPadding + std::max( |
196 std::max(title_size.height(), close_button_size.height()), | 218 std::max(title_size.height(), close_button_size.height()), |
197 throbber_size.height()); | 219 throbber_size.height()); |
198 } | 220 } |
199 client_view_bounds_.SetRect(insets.left(), top_height, | 221 client_view_bounds_.SetRect(insets.left(), top_height, |
200 std::max(0, width() - insets.width()), | 222 std::max(0, width() - insets.width()), |
201 std::max(0, height() - top_height - insets.bottom())); | 223 std::max(0, height() - top_height - insets.bottom())); |
(...skipping 12 matching lines...) Expand all Loading... |
214 canvas->GetSkCanvas()->drawPath(path, paint); | 236 canvas->GetSkCanvas()->drawPath(path, paint); |
215 } | 237 } |
216 | 238 |
217 void BubbleFrameView::ButtonPressed(views::Button* sender, | 239 void BubbleFrameView::ButtonPressed(views::Button* sender, |
218 const views::Event& event) { | 240 const views::Event& event) { |
219 if (close_button_ != NULL && sender == close_button_) | 241 if (close_button_ != NULL && sender == close_button_) |
220 frame_->Close(); | 242 frame_->Close(); |
221 } | 243 } |
222 | 244 |
223 } // namespace chromeos | 245 } // namespace chromeos |
OLD | NEW |