| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // +---------------------------------+ | 65 // +---------------------------------+ |
| 66 if (vertical) | 66 if (vertical) |
| 67 return std::max(0, available_bounds.y() - window_bounds.y()) + | 67 return std::max(0, available_bounds.y() - window_bounds.y()) + |
| 68 std::max(0, window_bounds.bottom() - available_bounds.bottom()); | 68 std::max(0, window_bounds.bottom() - available_bounds.bottom()); |
| 69 return std::max(0, available_bounds.x() - window_bounds.x()) + | 69 return std::max(0, available_bounds.x() - window_bounds.x()) + |
| 70 std::max(0, window_bounds.right() - available_bounds.right()); | 70 std::max(0, window_bounds.right() - available_bounds.right()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace | 73 } // namespace |
| 74 | 74 |
| 75 // A container that changes visibility with its contents. |
| 76 class FootnoteContainerView : public View { |
| 77 public: |
| 78 FootnoteContainerView() {} |
| 79 |
| 80 // View: |
| 81 void ChildVisibilityChanged(View* child) override { |
| 82 DCHECK_EQ(child_count(), 1); |
| 83 SetVisible(child->visible()); |
| 84 } |
| 85 |
| 86 private: |
| 87 DISALLOW_COPY_AND_ASSIGN(FootnoteContainerView); |
| 88 }; |
| 89 |
| 75 // static | 90 // static |
| 76 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; | 91 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; |
| 77 | 92 |
| 78 BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins, | 93 BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins, |
| 79 const gfx::Insets& content_margins) | 94 const gfx::Insets& content_margins) |
| 80 : bubble_border_(nullptr), | 95 : bubble_border_(nullptr), |
| 81 title_margins_(title_margins), | 96 title_margins_(title_margins), |
| 82 content_margins_(content_margins), | 97 content_margins_(content_margins), |
| 83 title_icon_(new views::ImageView()), | 98 title_icon_(new views::ImageView()), |
| 84 default_title_(CreateDefaultTitleLabel(base::string16()).release()), | 99 default_title_(CreateDefaultTitleLabel(base::string16()).release()), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // not affect screen readers' ability to focus the close button. Keyboard | 153 // not affect screen readers' ability to focus the close button. Keyboard |
| 139 // access to the close button when not using a screen reader is done via the | 154 // access to the close button when not using a screen reader is done via the |
| 140 // ESC key handler in DialogClientView. | 155 // ESC key handler in DialogClientView. |
| 141 close_button->SetFocusBehavior(View::FocusBehavior::NEVER); | 156 close_button->SetFocusBehavior(View::FocusBehavior::NEVER); |
| 142 return close_button; | 157 return close_button; |
| 143 } | 158 } |
| 144 | 159 |
| 145 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { | 160 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { |
| 146 gfx::Rect client_bounds = GetContentsBounds(); | 161 gfx::Rect client_bounds = GetContentsBounds(); |
| 147 client_bounds.Inset(GetInsets()); | 162 client_bounds.Inset(GetInsets()); |
| 148 if (footnote_container_) { | 163 // Only account for footnote_container_'s height if it's visible, because |
| 164 // content_margins_ adds extra padding even if all child views are invisible. |
| 165 if (footnote_container_ && footnote_container_->visible()) { |
| 149 client_bounds.set_height(client_bounds.height() - | 166 client_bounds.set_height(client_bounds.height() - |
| 150 footnote_container_->height()); | 167 footnote_container_->height()); |
| 151 } | 168 } |
| 152 return client_bounds; | 169 return client_bounds; |
| 153 } | 170 } |
| 154 | 171 |
| 155 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( | 172 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( |
| 156 const gfx::Rect& client_bounds) const { | 173 const gfx::Rect& client_bounds) const { |
| 157 gfx::Size size(GetSizeForClientSize(client_bounds.size())); | 174 gfx::Size size(GetSizeForClientSize(client_bounds.size())); |
| 158 return bubble_border_->GetBounds(gfx::Rect(), size); | 175 return bubble_border_->GetBounds(gfx::Rect(), size); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 title()->GetHeightForWidth(title_available_width); | 374 title()->GetHeightForWidth(title_available_width); |
| 358 const int title_height = | 375 const int title_height = |
| 359 std::max(title_icon_pref_size.height(), title_preferred_height); | 376 std::max(title_icon_pref_size.height(), title_preferred_height); |
| 360 title()->SetBounds(title_label_x, | 377 title()->SetBounds(title_label_x, |
| 361 bounds.y() + (title_height - title_preferred_height) / 2, | 378 bounds.y() + (title_height - title_preferred_height) / 2, |
| 362 title_available_width, title_height); | 379 title_available_width, title_height); |
| 363 | 380 |
| 364 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), | 381 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), |
| 365 title_height); | 382 title_height); |
| 366 | 383 |
| 367 if (footnote_container_) { | 384 // Only account for footnote_container_'s height if it's visible, because |
| 385 // content_margins_ adds extra padding even if all child views are invisible. |
| 386 if (footnote_container_ && footnote_container_->visible()) { |
| 368 const int width = contents_bounds.width(); | 387 const int width = contents_bounds.width(); |
| 369 const int height = footnote_container_->GetHeightForWidth(width); | 388 const int height = footnote_container_->GetHeightForWidth(width); |
| 370 footnote_container_->SetBounds( | 389 footnote_container_->SetBounds( |
| 371 contents_bounds.x(), contents_bounds.bottom() - height, width, height); | 390 contents_bounds.x(), contents_bounds.bottom() - height, width, height); |
| 372 } | 391 } |
| 373 } | 392 } |
| 374 | 393 |
| 375 void BubbleFrameView::OnThemeChanged() { | 394 void BubbleFrameView::OnThemeChanged() { |
| 376 UpdateWindowTitle(); | 395 UpdateWindowTitle(); |
| 377 ResetWindowControls(); | 396 ResetWindowControls(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 447 |
| 429 // Update the background, which relies on the border. | 448 // Update the background, which relies on the border. |
| 430 SetBackground(base::MakeUnique<views::BubbleBackground>(bubble_border_)); | 449 SetBackground(base::MakeUnique<views::BubbleBackground>(bubble_border_)); |
| 431 } | 450 } |
| 432 | 451 |
| 433 void BubbleFrameView::SetFootnoteView(View* view) { | 452 void BubbleFrameView::SetFootnoteView(View* view) { |
| 434 if (!view) | 453 if (!view) |
| 435 return; | 454 return; |
| 436 | 455 |
| 437 DCHECK(!footnote_container_); | 456 DCHECK(!footnote_container_); |
| 438 footnote_container_ = new views::View(); | 457 footnote_container_ = new FootnoteContainerView(); |
| 439 footnote_container_->SetLayoutManager( | 458 footnote_container_->SetLayoutManager( |
| 440 new BoxLayout(BoxLayout::kVertical, content_margins_, 0)); | 459 new BoxLayout(BoxLayout::kVertical, content_margins_, 0)); |
| 441 footnote_container_->SetBackground( | 460 footnote_container_->SetBackground( |
| 442 CreateSolidBackground(kFootnoteBackgroundColor)); | 461 CreateSolidBackground(kFootnoteBackgroundColor)); |
| 443 footnote_container_->SetBorder( | 462 footnote_container_->SetBorder( |
| 444 CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor)); | 463 CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor)); |
| 445 footnote_container_->AddChildView(view); | 464 footnote_container_->AddChildView(view); |
| 465 footnote_container_->SetVisible(view->visible()); |
| 446 AddChildView(footnote_container_); | 466 AddChildView(footnote_container_); |
| 447 } | 467 } |
| 448 | 468 |
| 449 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, | 469 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, |
| 450 const gfx::Size& client_size, | 470 const gfx::Size& client_size, |
| 451 bool adjust_if_offscreen) { | 471 bool adjust_if_offscreen) { |
| 452 gfx::Size size(GetSizeForClientSize(client_size)); | 472 gfx::Size size(GetSizeForClientSize(client_size)); |
| 453 | 473 |
| 454 const BubbleBorder::Arrow arrow = bubble_border_->arrow(); | 474 const BubbleBorder::Arrow arrow = bubble_border_->arrow(); |
| 455 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) { | 475 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 title_bar_width += title_margins_.left(); | 581 title_bar_width += title_margins_.left(); |
| 562 title_bar_width += title_icon_size.width(); | 582 title_bar_width += title_icon_size.width(); |
| 563 if (close_->visible()) | 583 if (close_->visible()) |
| 564 title_bar_width += close_->width() + 1; | 584 title_bar_width += close_->width() + 1; |
| 565 | 585 |
| 566 gfx::Size size(client_size); | 586 gfx::Size size(client_size); |
| 567 gfx::Insets client_insets = GetInsets(); | 587 gfx::Insets client_insets = GetInsets(); |
| 568 size.Enlarge(client_insets.width(), client_insets.height()); | 588 size.Enlarge(client_insets.width(), client_insets.height()); |
| 569 size.SetToMax(gfx::Size(title_bar_width, 0)); | 589 size.SetToMax(gfx::Size(title_bar_width, 0)); |
| 570 | 590 |
| 571 if (footnote_container_) | 591 // Only account for footnote_container_'s height if it's visible, because |
| 592 // content_margins_ adds extra padding even if all child views are invisible. |
| 593 if (footnote_container_ && footnote_container_->visible()) |
| 572 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 594 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
| 573 | 595 |
| 574 DialogDelegate* dialog_delegate = | 596 DialogDelegate* dialog_delegate = |
| 575 GetWidget()->widget_delegate()->AsDialogDelegate(); | 597 GetWidget()->widget_delegate()->AsDialogDelegate(); |
| 576 if (dialog_delegate && dialog_delegate->ShouldSnapFrameWidth()) | 598 if (dialog_delegate && dialog_delegate->ShouldSnapFrameWidth()) |
| 577 size.set_width(LayoutProvider::Get()->GetSnappedDialogWidth(size.width())); | 599 size.set_width(LayoutProvider::Get()->GetSnappedDialogWidth(size.width())); |
| 578 | 600 |
| 579 return size; | 601 return size; |
| 580 } | 602 } |
| 581 | 603 |
| 582 } // namespace views | 604 } // namespace views |
| OLD | NEW |