| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "ui/views/layout/layout_constants.h" | 26 #include "ui/views/layout/layout_constants.h" |
| 27 #include "ui/views/resources/grit/views_resources.h" | 27 #include "ui/views/resources/grit/views_resources.h" |
| 28 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 29 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
| 30 #include "ui/views/window/client_view.h" | 30 #include "ui/views/window/client_view.h" |
| 31 | 31 |
| 32 namespace views { | 32 namespace views { |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // The horizontal padding between the title and the icon. | |
| 37 const int kTitleHorizontalPadding = 5; | |
| 38 | |
| 39 // Background color of the footnote view. | 36 // Background color of the footnote view. |
| 40 const SkColor kFootnoteBackgroundColor = SkColorSetRGB(245, 245, 245); | 37 const SkColor kFootnoteBackgroundColor = SkColorSetRGB(245, 245, 245); |
| 41 | 38 |
| 42 // Color of the top border of the footnote. | 39 // Color of the top border of the footnote. |
| 43 const SkColor kFootnoteBorderColor = SkColorSetRGB(229, 229, 229); | 40 const SkColor kFootnoteBorderColor = SkColorSetRGB(229, 229, 229); |
| 44 | 41 |
| 45 // Get the |vertical| or horizontal amount that |available_bounds| overflows | 42 // Get the |vertical| or horizontal amount that |available_bounds| overflows |
| 46 // |window_bounds|. | 43 // |window_bounds|. |
| 47 int GetOffScreenLength(const gfx::Rect& available_bounds, | 44 int GetOffScreenLength(const gfx::Rect& available_bounds, |
| 48 const gfx::Rect& window_bounds, | 45 const gfx::Rect& window_bounds, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 133 } |
| 137 | 134 |
| 138 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { | 135 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { |
| 139 if (!bounds().Contains(point)) | 136 if (!bounds().Contains(point)) |
| 140 return HTNOWHERE; | 137 return HTNOWHERE; |
| 141 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) | 138 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) |
| 142 return HTCLOSE; | 139 return HTCLOSE; |
| 143 | 140 |
| 144 // Allow dialogs to show the system menu and be dragged. | 141 // Allow dialogs to show the system menu and be dragged. |
| 145 if (GetWidget()->widget_delegate()->AsDialogDelegate()) { | 142 if (GetWidget()->widget_delegate()->AsDialogDelegate()) { |
| 146 gfx::Rect sys_rect(0, 0, title_->x(), title_->y()); | 143 gfx::Rect bounds(GetContentsBounds()); |
| 144 bounds.Inset(title_margins_); |
| 145 gfx::Rect sys_rect(0, 0, bounds.x(), bounds.y()); |
| 147 sys_rect.set_origin(gfx::Point(GetMirroredXForRect(sys_rect), 0)); | 146 sys_rect.set_origin(gfx::Point(GetMirroredXForRect(sys_rect), 0)); |
| 148 if (sys_rect.Contains(point)) | 147 if (sys_rect.Contains(point)) |
| 149 return HTSYSMENU; | 148 return HTSYSMENU; |
| 150 if (point.y() < title_->bounds().bottom()) | 149 if (point.y() < title_->bounds().bottom()) |
| 151 return HTCAPTION; | 150 return HTCAPTION; |
| 152 } | 151 } |
| 153 | 152 |
| 154 return GetWidget()->client_view()->NonClientHitTest(point); | 153 return GetWidget()->client_view()->NonClientHitTest(point); |
| 155 } | 154 } |
| 156 | 155 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 gfx::Rect bounds(GetContentsBounds()); | 274 gfx::Rect bounds(GetContentsBounds()); |
| 276 bounds.Inset(title_margins_); | 275 bounds.Inset(title_margins_); |
| 277 if (bounds.IsEmpty()) | 276 if (bounds.IsEmpty()) |
| 278 return; | 277 return; |
| 279 | 278 |
| 280 // The close button is positioned somewhat closer to the edge of the bubble. | 279 // The close button is positioned somewhat closer to the edge of the bubble. |
| 281 gfx::Point close_position = GetContentsBounds().top_right(); | 280 gfx::Point close_position = GetContentsBounds().top_right(); |
| 282 close_position += gfx::Vector2d(-close_->width() - 7, 6); | 281 close_position += gfx::Vector2d(-close_->width() - 7, 6); |
| 283 close_->SetPosition(close_position); | 282 close_->SetPosition(close_position); |
| 284 | 283 |
| 285 gfx::Size title_icon_size(title_icon_->GetPreferredSize()); | 284 gfx::Size title_icon_pref_size(title_icon_->GetPreferredSize()); |
| 286 gfx::Size title_label_size(title_->GetPreferredSize()); | |
| 287 int padding = 0; | 285 int padding = 0; |
| 288 if (title_icon_size.width() > 0 && title_label_size.width() > 0) | |
| 289 padding = kTitleHorizontalPadding; | |
| 290 const int title_height = std::max(title_icon_size.height(), | |
| 291 title_label_size.height()); | |
| 292 | 286 |
| 293 const int title_icon_width = std::max(0, close_->x() - bounds.x()); | 287 if (title_->visible() && !title_->text().empty()) { |
| 294 title_icon_size.SetToMin(gfx::Size(title_icon_width, title_height)); | 288 if (title_icon_pref_size.width() > 0) |
| 295 gfx::Rect title_icon_bounds( | 289 padding = title_margins_.left(); |
| 296 bounds.x(), bounds.y(), title_icon_size.width(), title_height); | |
| 297 title_icon_->SetBoundsRect(title_icon_bounds); | |
| 298 | 290 |
| 299 const int title_label_x = title_icon_->bounds().right() + padding; | 291 const int title_label_x = |
| 300 const int title_label_width = std::max(0, close_->x() - title_label_x); | 292 bounds.x() + title_icon_pref_size.width() + padding; |
| 301 title_label_size.SetToMin(gfx::Size(title_label_width, | 293 title_->SizeToFit(std::max(1, close_->x() - title_label_x)); |
| 302 title_label_size.height())); | 294 title_->SetPosition(gfx::Point(title_label_x, bounds.y())); |
| 303 gfx::Rect title_label_bounds( | 295 } |
| 304 title_label_x, bounds.y(), title_label_size.width(), title_height); | |
| 305 title_->SetBoundsRect(title_label_bounds); | |
| 306 | 296 |
| 307 bounds.set_width( | 297 const int title_height = |
| 308 title_icon_size.width() + title_label_size.width() + padding); | 298 std::max(title_icon_pref_size.height(), title_->height()); |
| 299 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), |
| 300 title_height); |
| 301 bounds.set_width(title_->bounds().right() - bounds.x()); |
| 309 bounds.set_height(title_height); | 302 bounds.set_height(title_height); |
| 310 | 303 |
| 311 if (titlebar_extra_view_) { | 304 if (titlebar_extra_view_) { |
| 312 const int extra_width = close_->x() - bounds.right(); | 305 const int extra_width = close_->x() - bounds.right(); |
| 313 gfx::Size size = titlebar_extra_view_->GetPreferredSize(); | 306 gfx::Size size = titlebar_extra_view_->GetPreferredSize(); |
| 314 size.SetToMin(gfx::Size(std::max(0, extra_width), size.height())); | 307 size.SetToMin(gfx::Size(std::max(0, extra_width), size.height())); |
| 315 gfx::Rect titlebar_extra_view_bounds( | 308 gfx::Rect titlebar_extra_view_bounds( |
| 316 close_->x() - size.width(), | 309 close_->x() - size.width(), |
| 317 bounds.y(), | 310 bounds.y(), |
| 318 size.width(), | 311 size.width(), |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 SchedulePaint(); | 493 SchedulePaint(); |
| 501 } | 494 } |
| 502 | 495 |
| 503 gfx::Size BubbleFrameView::GetSizeForClientSize( | 496 gfx::Size BubbleFrameView::GetSizeForClientSize( |
| 504 const gfx::Size& client_size) const { | 497 const gfx::Size& client_size) const { |
| 505 // Accommodate the width of the title bar elements. | 498 // Accommodate the width of the title bar elements. |
| 506 int title_bar_width = title_margins_.width() + border()->GetInsets().width(); | 499 int title_bar_width = title_margins_.width() + border()->GetInsets().width(); |
| 507 gfx::Size title_icon_size = title_icon_->GetPreferredSize(); | 500 gfx::Size title_icon_size = title_icon_->GetPreferredSize(); |
| 508 gfx::Size title_label_size = title_->GetPreferredSize(); | 501 gfx::Size title_label_size = title_->GetPreferredSize(); |
| 509 if (title_icon_size.width() > 0 && title_label_size.width() > 0) | 502 if (title_icon_size.width() > 0 && title_label_size.width() > 0) |
| 510 title_bar_width += kTitleHorizontalPadding; | 503 title_bar_width += title_margins_.left(); |
| 511 title_bar_width += title_icon_size.width(); | 504 title_bar_width += title_icon_size.width(); |
| 512 if (close_->visible()) | 505 if (close_->visible()) |
| 513 title_bar_width += close_->width() + 1; | 506 title_bar_width += close_->width() + 1; |
| 514 if (titlebar_extra_view_) | 507 if (titlebar_extra_view_) |
| 515 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); | 508 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); |
| 516 | 509 |
| 517 gfx::Size size(client_size); | 510 gfx::Size size(client_size); |
| 518 gfx::Insets client_insets = GetInsets(); | 511 gfx::Insets client_insets = GetInsets(); |
| 519 size.Enlarge(client_insets.width(), client_insets.height()); | 512 size.Enlarge(client_insets.width(), client_insets.height()); |
| 520 size.SetToMax(gfx::Size(title_bar_width, 0)); | 513 size.SetToMax(gfx::Size(title_bar_width, 0)); |
| 521 | 514 |
| 522 if (footnote_container_) | 515 if (footnote_container_) |
| 523 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 516 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
| 524 | 517 |
| 525 return size; | 518 return size; |
| 526 } | 519 } |
| 527 | 520 |
| 528 } // namespace views | 521 } // namespace views |
| OLD | NEW |