Chromium Code Reviews| 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 // Simple container to bubble child view changes up the view hierarchy. | |
|
msw
2017/07/05 20:45:30
nit: s/bubble/propagate/, or consider "A container
Jared Saul
2017/07/07 20:12:27
Done; took your full suggestion.
| |
| 76 class BubbleFrameView::FootnoteContainerView : public View { | |
| 77 public: | |
| 78 FootnoteContainerView() {} | |
| 79 | |
| 80 void UpdateVisibility() { | |
| 81 if (child_count() >= 1) { | |
|
tapted
2017/07/06 01:11:58
I think this is always true? ChildVisibilityChange
Jared Saul
2017/07/07 20:12:27
Done.
| |
| 82 SetVisible(child_at(0)->visible()); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 // View: | |
| 87 void ChildVisibilityChanged(View* child) override { UpdateVisibility(); } | |
| 88 | |
| 89 private: | |
| 90 DISALLOW_COPY_AND_ASSIGN(FootnoteContainerView); | |
| 91 }; | |
| 92 | |
| 75 // static | 93 // static |
| 76 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; | 94 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; |
| 77 | 95 |
| 78 BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins, | 96 BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins, |
| 79 const gfx::Insets& content_margins) | 97 const gfx::Insets& content_margins) |
| 80 : bubble_border_(nullptr), | 98 : bubble_border_(nullptr), |
| 81 title_margins_(title_margins), | 99 title_margins_(title_margins), |
| 82 content_margins_(content_margins), | 100 content_margins_(content_margins), |
| 83 title_icon_(new views::ImageView()), | 101 title_icon_(new views::ImageView()), |
| 84 title_(nullptr), | 102 title_(nullptr), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 *rb->GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); | 143 *rb->GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); |
| 126 } | 144 } |
| 127 close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); | 145 close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); |
| 128 close_button->SizeToPreferredSize(); | 146 close_button->SizeToPreferredSize(); |
| 129 return close_button; | 147 return close_button; |
| 130 } | 148 } |
| 131 | 149 |
| 132 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { | 150 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { |
| 133 gfx::Rect client_bounds = GetContentsBounds(); | 151 gfx::Rect client_bounds = GetContentsBounds(); |
| 134 client_bounds.Inset(GetInsets()); | 152 client_bounds.Inset(GetInsets()); |
| 135 if (footnote_container_) { | 153 // Only account for footnote_container_'s height if it's visible, because |
| 154 // content_margins_ adds extra padding even if all child views are invisible. | |
| 155 if (footnote_container_ && footnote_container_->visible()) { | |
| 136 client_bounds.set_height(client_bounds.height() - | 156 client_bounds.set_height(client_bounds.height() - |
| 137 footnote_container_->height()); | 157 footnote_container_->height()); |
| 138 } | 158 } |
| 139 return client_bounds; | 159 return client_bounds; |
| 140 } | 160 } |
| 141 | 161 |
| 142 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( | 162 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( |
| 143 const gfx::Rect& client_bounds) const { | 163 const gfx::Rect& client_bounds) const { |
| 144 gfx::Size size(GetSizeForClientSize(client_bounds.size())); | 164 gfx::Size size(GetSizeForClientSize(client_bounds.size())); |
| 145 return bubble_border_->GetBounds(gfx::Rect(), size); | 165 return bubble_border_->GetBounds(gfx::Rect(), size); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 title_height = std::max(title_height, title_->height()); | 353 title_height = std::max(title_height, title_->height()); |
| 334 title_->SetPosition(gfx::Point( | 354 title_->SetPosition(gfx::Point( |
| 335 title_label_x, bounds.y() + (title_height - title_->height()) / 2)); | 355 title_label_x, bounds.y() + (title_height - title_->height()) / 2)); |
| 336 } | 356 } |
| 337 | 357 |
| 338 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), | 358 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), |
| 339 title_height); | 359 title_height); |
| 340 bounds.set_width(title_->bounds().right() - bounds.x()); | 360 bounds.set_width(title_->bounds().right() - bounds.x()); |
| 341 bounds.set_height(title_height); | 361 bounds.set_height(title_height); |
| 342 | 362 |
| 343 if (footnote_container_) { | 363 // Only account for footnote_container_'s height if it's visible, because |
| 364 // content_margins_ adds extra padding even if all child views are invisible. | |
| 365 if (footnote_container_ && footnote_container_->visible()) { | |
| 344 const int width = contents_bounds.width(); | 366 const int width = contents_bounds.width(); |
| 345 const int height = footnote_container_->GetHeightForWidth(width); | 367 const int height = footnote_container_->GetHeightForWidth(width); |
| 346 footnote_container_->SetBounds( | 368 footnote_container_->SetBounds( |
| 347 contents_bounds.x(), contents_bounds.bottom() - height, width, height); | 369 contents_bounds.x(), contents_bounds.bottom() - height, width, height); |
| 348 } | 370 } |
| 349 } | 371 } |
| 350 | 372 |
| 351 void BubbleFrameView::OnThemeChanged() { | 373 void BubbleFrameView::OnThemeChanged() { |
| 352 UpdateWindowTitle(); | 374 UpdateWindowTitle(); |
| 353 ResetWindowControls(); | 375 ResetWindowControls(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 401 | 423 |
| 402 // Update the background, which relies on the border. | 424 // Update the background, which relies on the border. |
| 403 SetBackground(base::MakeUnique<views::BubbleBackground>(bubble_border_)); | 425 SetBackground(base::MakeUnique<views::BubbleBackground>(bubble_border_)); |
| 404 } | 426 } |
| 405 | 427 |
| 406 void BubbleFrameView::SetFootnoteView(View* view) { | 428 void BubbleFrameView::SetFootnoteView(View* view) { |
| 407 if (!view) | 429 if (!view) |
| 408 return; | 430 return; |
| 409 | 431 |
| 410 DCHECK(!footnote_container_); | 432 DCHECK(!footnote_container_); |
| 411 footnote_container_ = new views::View(); | 433 footnote_container_ = new FootnoteContainerView(); |
|
tapted
2017/07/06 01:11:59
I see msw commented about this in the test :) - th
Jared Saul
2017/07/07 20:12:27
Thanks; this was really useful.
| |
| 412 footnote_container_->SetLayoutManager( | 434 footnote_container_->SetLayoutManager( |
| 413 new BoxLayout(BoxLayout::kVertical, content_margins_, 0)); | 435 new BoxLayout(BoxLayout::kVertical, content_margins_, 0)); |
| 414 footnote_container_->SetBackground( | 436 footnote_container_->SetBackground( |
| 415 CreateSolidBackground(kFootnoteBackgroundColor)); | 437 CreateSolidBackground(kFootnoteBackgroundColor)); |
| 416 footnote_container_->SetBorder( | 438 footnote_container_->SetBorder( |
| 417 CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor)); | 439 CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor)); |
| 418 footnote_container_->AddChildView(view); | 440 footnote_container_->AddChildView(view); |
| 441 footnote_container_->UpdateVisibility(); | |
|
tapted
2017/07/06 01:11:58
or, perhaps simpler, just call
footnote_container
Jared Saul
2017/07/07 20:12:28
Done.
| |
| 419 AddChildView(footnote_container_); | 442 AddChildView(footnote_container_); |
| 420 } | 443 } |
| 421 | 444 |
| 422 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, | 445 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, |
| 423 const gfx::Size& client_size, | 446 const gfx::Size& client_size, |
| 424 bool adjust_if_offscreen) { | 447 bool adjust_if_offscreen) { |
| 425 gfx::Size size(GetSizeForClientSize(client_size)); | 448 gfx::Size size(GetSizeForClientSize(client_size)); |
| 426 | 449 |
| 427 const BubbleBorder::Arrow arrow = bubble_border_->arrow(); | 450 const BubbleBorder::Arrow arrow = bubble_border_->arrow(); |
| 428 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) { | 451 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 title_bar_width += title_margins_.left(); | 557 title_bar_width += title_margins_.left(); |
| 535 title_bar_width += title_icon_size.width(); | 558 title_bar_width += title_icon_size.width(); |
| 536 if (close_->visible()) | 559 if (close_->visible()) |
| 537 title_bar_width += close_->width() + 1; | 560 title_bar_width += close_->width() + 1; |
| 538 | 561 |
| 539 gfx::Size size(client_size); | 562 gfx::Size size(client_size); |
| 540 gfx::Insets client_insets = GetInsets(); | 563 gfx::Insets client_insets = GetInsets(); |
| 541 size.Enlarge(client_insets.width(), client_insets.height()); | 564 size.Enlarge(client_insets.width(), client_insets.height()); |
| 542 size.SetToMax(gfx::Size(title_bar_width, 0)); | 565 size.SetToMax(gfx::Size(title_bar_width, 0)); |
| 543 | 566 |
| 544 if (footnote_container_) | 567 // Only account for footnote_container_'s height if it's visible, because |
| 568 // content_margins_ adds extra padding even if all child views are invisible. | |
| 569 if (footnote_container_ && footnote_container_->visible()) | |
| 545 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 570 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
| 546 | 571 |
| 547 DialogDelegate* dialog_delegate = | 572 DialogDelegate* dialog_delegate = |
| 548 GetWidget()->widget_delegate()->AsDialogDelegate(); | 573 GetWidget()->widget_delegate()->AsDialogDelegate(); |
| 549 if (dialog_delegate && dialog_delegate->ShouldSnapFrameWidth()) | 574 if (dialog_delegate && dialog_delegate->ShouldSnapFrameWidth()) |
| 550 size.set_width(LayoutProvider::Get()->GetSnappedDialogWidth(size.width())); | 575 size.set_width(LayoutProvider::Get()->GetSnappedDialogWidth(size.width())); |
| 551 | 576 |
| 552 return size; | 577 return size; |
| 553 } | 578 } |
| 554 | 579 |
| 555 } // namespace views | 580 } // namespace views |
| OLD | NEW |