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 "ui/views/bubble/bubble_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
10 #include "ui/base/hit_test.h" | 10 #include "ui/base/hit_test.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 gfx::Insets BubbleFrameView::GetInsets() const { | 161 gfx::Insets BubbleFrameView::GetInsets() const { |
162 gfx::Insets insets = content_margins_; | 162 gfx::Insets insets = content_margins_; |
163 const int title_height = title_->text().empty() ? 0 : | 163 const int title_height = title_->text().empty() ? 0 : |
164 title_->GetPreferredSize().height() + kTitleTopInset + kTitleBottomInset; | 164 title_->GetPreferredSize().height() + kTitleTopInset + kTitleBottomInset; |
165 const int close_height = close_->visible() ? close_->height() : 0; | 165 const int close_height = close_->visible() ? close_->height() : 0; |
166 insets += gfx::Insets(std::max(title_height, close_height), 0, 0, 0); | 166 insets += gfx::Insets(std::max(title_height, close_height), 0, 0, 0); |
167 return insets; | 167 return insets; |
168 } | 168 } |
169 | 169 |
170 gfx::Size BubbleFrameView::GetPreferredSize() { | 170 gfx::Size BubbleFrameView::GetPreferredSize() { |
171 const gfx::Size client(GetWidget()->client_view()->GetPreferredSize()); | 171 return GetSizeForClientSize(GetWidget()->client_view()->GetPreferredSize()); |
172 gfx::Size size(GetUpdatedWindowBounds(gfx::Rect(), client, false).size()); | 172 } |
173 // Accommodate the width of the title bar elements. | 173 |
174 int title_bar_width = GetInsets().width() + border()->GetInsets().width(); | 174 gfx::Size BubbleFrameView::GetMinimumSize() { |
175 if (!title_->text().empty()) | 175 return GetSizeForClientSize(GetWidget()->client_view()->GetMinimumSize()); |
176 title_bar_width += kTitleLeftInset + title_->GetPreferredSize().width(); | |
177 if (close_->visible()) | |
178 title_bar_width += close_->width() + 1; | |
179 if (titlebar_extra_view_ != NULL) | |
180 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); | |
181 size.SetToMax(gfx::Size(title_bar_width, 0)); | |
182 return size; | |
183 } | 176 } |
184 | 177 |
185 void BubbleFrameView::Layout() { | 178 void BubbleFrameView::Layout() { |
186 gfx::Rect bounds(GetLocalBounds()); | 179 gfx::Rect bounds(GetLocalBounds()); |
187 bounds.Inset(border()->GetInsets()); | 180 bounds.Inset(border()->GetInsets()); |
188 // Small additional insets yield the desired 10px visual close button insets. | 181 // Small additional insets yield the desired 10px visual close button insets. |
189 bounds.Inset(0, 0, close_->width() + 1, 0); | 182 bounds.Inset(0, 0, close_->width() + 1, 0); |
190 close_->SetPosition(gfx::Point(bounds.right(), bounds.y() + 2)); | 183 close_->SetPosition(gfx::Point(bounds.right(), bounds.y() + 2)); |
191 | 184 |
192 gfx::Rect title_bounds(bounds); | 185 gfx::Rect title_bounds(bounds); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // For center arrows, arrows are moved in the opposite direction of | 320 // For center arrows, arrows are moved in the opposite direction of |
328 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble | 321 // |offscreen_adjust|, e.g. positive |offscreen_adjust| means bubble |
329 // window needs to be moved to the right and that means we need to move arrow | 322 // window needs to be moved to the right and that means we need to move arrow |
330 // to the left, and that means negative offset. | 323 // to the left, and that means negative offset. |
331 bubble_border_->set_arrow_offset( | 324 bubble_border_->set_arrow_offset( |
332 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); | 325 bubble_border_->GetArrowOffset(window_bounds.size()) - offscreen_adjust); |
333 if (offscreen_adjust) | 326 if (offscreen_adjust) |
334 SchedulePaint(); | 327 SchedulePaint(); |
335 } | 328 } |
336 | 329 |
| 330 gfx::Size BubbleFrameView::GetSizeForClientSize(const gfx::Size& client_size) { |
| 331 gfx::Size size( |
| 332 GetUpdatedWindowBounds(gfx::Rect(), client_size, false).size()); |
| 333 // Accommodate the width of the title bar elements. |
| 334 int title_bar_width = GetInsets().width() + border()->GetInsets().width(); |
| 335 if (!title_->text().empty()) |
| 336 title_bar_width += kTitleLeftInset + title_->GetPreferredSize().width(); |
| 337 if (close_->visible()) |
| 338 title_bar_width += close_->width() + 1; |
| 339 if (titlebar_extra_view_ != NULL) |
| 340 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); |
| 341 size.SetToMax(gfx::Size(title_bar_width, 0)); |
| 342 return size; |
| 343 } |
| 344 |
337 } // namespace views | 345 } // namespace views |
OLD | NEW |