| 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 17 matching lines...) Expand all Loading... |
| 28 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
| 29 #include "ui/views/resources/grit/views_resources.h" | 29 #include "ui/views/resources/grit/views_resources.h" |
| 30 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 31 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
| 32 #include "ui/views/window/client_view.h" | 32 #include "ui/views/window/client_view.h" |
| 33 | 33 |
| 34 namespace views { | 34 namespace views { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // The horizontal padding between the title and the icon. | |
| 39 const int kTitleHorizontalPadding = 5; | |
| 40 | |
| 41 // Background color of the footnote view. | 38 // Background color of the footnote view. |
| 42 const SkColor kFootnoteBackgroundColor = SkColorSetRGB(245, 245, 245); | 39 const SkColor kFootnoteBackgroundColor = SkColorSetRGB(245, 245, 245); |
| 43 | 40 |
| 44 // Color of the top border of the footnote. | 41 // Color of the top border of the footnote. |
| 45 const SkColor kFootnoteBorderColor = SkColorSetRGB(229, 229, 229); | 42 const SkColor kFootnoteBorderColor = SkColorSetRGB(229, 229, 229); |
| 46 | 43 |
| 47 // Get the |vertical| or horizontal amount that |available_bounds| overflows | 44 // Get the |vertical| or horizontal amount that |available_bounds| overflows |
| 48 // |window_bounds|. | 45 // |window_bounds|. |
| 49 int GetOffScreenLength(const gfx::Rect& available_bounds, | 46 int GetOffScreenLength(const gfx::Rect& available_bounds, |
| 50 const gfx::Rect& window_bounds, | 47 const gfx::Rect& window_bounds, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 149 |
| 153 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { | 150 int BubbleFrameView::NonClientHitTest(const gfx::Point& point) { |
| 154 if (!bounds().Contains(point)) | 151 if (!bounds().Contains(point)) |
| 155 return HTNOWHERE; | 152 return HTNOWHERE; |
| 156 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) | 153 if (close_->visible() && close_->GetMirroredBounds().Contains(point)) |
| 157 return HTCLOSE; | 154 return HTCLOSE; |
| 158 | 155 |
| 159 // Allow dialogs to show the system menu and be dragged. | 156 // Allow dialogs to show the system menu and be dragged. |
| 160 if (GetWidget()->widget_delegate()->AsDialogDelegate() && | 157 if (GetWidget()->widget_delegate()->AsDialogDelegate() && |
| 161 !GetWidget()->widget_delegate()->AsBubbleDialogDelegate()) { | 158 !GetWidget()->widget_delegate()->AsBubbleDialogDelegate()) { |
| 162 gfx::Rect sys_rect(0, 0, title_->x(), title_->y()); | 159 gfx::Rect bounds(GetContentsBounds()); |
| 160 bounds.Inset(title_margins_); |
| 161 gfx::Rect sys_rect(0, 0, bounds.x(), bounds.y()); |
| 163 sys_rect.set_origin(gfx::Point(GetMirroredXForRect(sys_rect), 0)); | 162 sys_rect.set_origin(gfx::Point(GetMirroredXForRect(sys_rect), 0)); |
| 164 if (sys_rect.Contains(point)) | 163 if (sys_rect.Contains(point)) |
| 165 return HTSYSMENU; | 164 return HTSYSMENU; |
| 166 if (point.y() < title_->bounds().bottom()) | 165 if (point.y() < title_->bounds().bottom()) |
| 167 return HTCAPTION; | 166 return HTCAPTION; |
| 168 } | 167 } |
| 169 | 168 |
| 170 return GetWidget()->client_view()->NonClientHitTest(point); | 169 return GetWidget()->client_view()->NonClientHitTest(point); |
| 171 } | 170 } |
| 172 | 171 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 gfx::Rect bounds(GetContentsBounds()); | 294 gfx::Rect bounds(GetContentsBounds()); |
| 296 bounds.Inset(title_margins_); | 295 bounds.Inset(title_margins_); |
| 297 if (bounds.IsEmpty()) | 296 if (bounds.IsEmpty()) |
| 298 return; | 297 return; |
| 299 | 298 |
| 300 // The close button is positioned somewhat closer to the edge of the bubble. | 299 // The close button is positioned somewhat closer to the edge of the bubble. |
| 301 gfx::Point close_position = GetContentsBounds().top_right(); | 300 gfx::Point close_position = GetContentsBounds().top_right(); |
| 302 close_position += gfx::Vector2d(-close_->width() - 7, 6); | 301 close_position += gfx::Vector2d(-close_->width() - 7, 6); |
| 303 close_->SetPosition(close_position); | 302 close_->SetPosition(close_position); |
| 304 | 303 |
| 305 gfx::Size title_icon_size(title_icon_->GetPreferredSize()); | 304 gfx::Size title_icon_pref_size(title_icon_->GetPreferredSize()); |
| 306 gfx::Size title_label_size(title_->GetPreferredSize()); | |
| 307 int padding = 0; | 305 int padding = 0; |
| 308 if (title_icon_size.width() > 0 && title_label_size.width() > 0) | |
| 309 padding = kTitleHorizontalPadding; | |
| 310 const int title_height = std::max(title_icon_size.height(), | |
| 311 title_label_size.height()); | |
| 312 | 306 |
| 313 const int title_icon_width = std::max(0, close_->x() - bounds.x()); | 307 if (title_->visible() && !title_->text().empty()) { |
| 314 title_icon_size.SetToMin(gfx::Size(title_icon_width, title_height)); | 308 if (title_icon_pref_size.width() > 0) |
| 315 gfx::Rect title_icon_bounds( | 309 padding = title_margins_.left(); |
| 316 bounds.x(), bounds.y(), title_icon_size.width(), title_height); | |
| 317 title_icon_->SetBoundsRect(title_icon_bounds); | |
| 318 | 310 |
| 319 const int title_label_x = title_icon_->bounds().right() + padding; | 311 const int title_label_x = |
| 320 const int title_label_width = std::max(0, close_->x() - title_label_x); | 312 bounds.x() + title_icon_pref_size.width() + padding; |
| 321 title_label_size.SetToMin(gfx::Size(title_label_width, | 313 title_->SizeToFit(std::max(1, close_->x() - title_label_x)); |
| 322 title_label_size.height())); | 314 title_->SetPosition(gfx::Point(title_label_x, bounds.y())); |
| 323 gfx::Rect title_label_bounds( | 315 } |
| 324 title_label_x, bounds.y(), title_label_size.width(), title_height); | |
| 325 title_->SetBoundsRect(title_label_bounds); | |
| 326 | 316 |
| 327 bounds.set_width( | 317 const int title_height = |
| 328 title_icon_size.width() + title_label_size.width() + padding); | 318 std::max(title_icon_pref_size.height(), title_->height()); |
| 319 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), |
| 320 title_height); |
| 321 bounds.set_width(title_->bounds().right() - bounds.x()); |
| 329 bounds.set_height(title_height); | 322 bounds.set_height(title_height); |
| 330 | 323 |
| 331 if (footnote_container_) { | 324 if (footnote_container_) { |
| 332 gfx::Rect local_bounds = GetContentsBounds(); | 325 gfx::Rect local_bounds = GetContentsBounds(); |
| 333 int height = footnote_container_->GetHeightForWidth(local_bounds.width()); | 326 int height = footnote_container_->GetHeightForWidth(local_bounds.width()); |
| 334 footnote_container_->SetBounds(local_bounds.x(), | 327 footnote_container_->SetBounds(local_bounds.x(), |
| 335 local_bounds.bottom() - height, | 328 local_bounds.bottom() - height, |
| 336 local_bounds.width(), height); | 329 local_bounds.width(), height); |
| 337 } | 330 } |
| 338 } | 331 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 SchedulePaint(); | 494 SchedulePaint(); |
| 502 } | 495 } |
| 503 | 496 |
| 504 gfx::Size BubbleFrameView::GetSizeForClientSize( | 497 gfx::Size BubbleFrameView::GetSizeForClientSize( |
| 505 const gfx::Size& client_size) const { | 498 const gfx::Size& client_size) const { |
| 506 // Accommodate the width of the title bar elements. | 499 // Accommodate the width of the title bar elements. |
| 507 int title_bar_width = title_margins_.width() + border()->GetInsets().width(); | 500 int title_bar_width = title_margins_.width() + border()->GetInsets().width(); |
| 508 gfx::Size title_icon_size = title_icon_->GetPreferredSize(); | 501 gfx::Size title_icon_size = title_icon_->GetPreferredSize(); |
| 509 gfx::Size title_label_size = title_->GetPreferredSize(); | 502 gfx::Size title_label_size = title_->GetPreferredSize(); |
| 510 if (title_icon_size.width() > 0 && title_label_size.width() > 0) | 503 if (title_icon_size.width() > 0 && title_label_size.width() > 0) |
| 511 title_bar_width += kTitleHorizontalPadding; | 504 title_bar_width += title_margins_.left(); |
| 512 title_bar_width += title_icon_size.width(); | 505 title_bar_width += title_icon_size.width(); |
| 513 if (close_->visible()) | 506 if (close_->visible()) |
| 514 title_bar_width += close_->width() + 1; | 507 title_bar_width += close_->width() + 1; |
| 515 | 508 |
| 516 gfx::Size size(client_size); | 509 gfx::Size size(client_size); |
| 517 gfx::Insets client_insets = GetInsets(); | 510 gfx::Insets client_insets = GetInsets(); |
| 518 size.Enlarge(client_insets.width(), client_insets.height()); | 511 size.Enlarge(client_insets.width(), client_insets.height()); |
| 519 size.SetToMax(gfx::Size(title_bar_width, 0)); | 512 size.SetToMax(gfx::Size(title_bar_width, 0)); |
| 520 | 513 |
| 521 if (footnote_container_) | 514 if (footnote_container_) |
| 522 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 515 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
| 523 | 516 |
| 524 return size; | 517 return size; |
| 525 } | 518 } |
| 526 | 519 |
| 527 } // namespace views | 520 } // namespace views |
| OLD | NEW |