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