Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: ui/views/bubble/bubble_frame_view.cc

Issue 2955963002: Update Chrome Upstream flow to reflect new UI mocks (Closed)
Patch Set: Actioning code review comments from Patch Set 4 Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(child_count() >= 1);
tapted 2017/07/10 03:52:05 nit: Is there a reason to use >= rather than == ?
Jared Saul 2017/07/10 19:24:40 No big reason; just an abundance of caution in cas
83 SetVisible(child_at(0)->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 title_(nullptr), 99 title_(nullptr),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 *rb->GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); 140 *rb->GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia());
126 } 141 }
127 close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); 142 close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE));
128 close_button->SizeToPreferredSize(); 143 close_button->SizeToPreferredSize();
129 return close_button; 144 return close_button;
130 } 145 }
131 146
132 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { 147 gfx::Rect BubbleFrameView::GetBoundsForClientView() const {
133 gfx::Rect client_bounds = GetContentsBounds(); 148 gfx::Rect client_bounds = GetContentsBounds();
134 client_bounds.Inset(GetInsets()); 149 client_bounds.Inset(GetInsets());
135 if (footnote_container_) { 150 // Only account for footnote_container_'s height if it's visible, because
151 // content_margins_ adds extra padding even if all child views are invisible.
152 if (footnote_container_ && footnote_container_->visible()) {
136 client_bounds.set_height(client_bounds.height() - 153 client_bounds.set_height(client_bounds.height() -
137 footnote_container_->height()); 154 footnote_container_->height());
138 } 155 }
139 return client_bounds; 156 return client_bounds;
140 } 157 }
141 158
142 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds( 159 gfx::Rect BubbleFrameView::GetWindowBoundsForClientBounds(
143 const gfx::Rect& client_bounds) const { 160 const gfx::Rect& client_bounds) const {
144 gfx::Size size(GetSizeForClientSize(client_bounds.size())); 161 gfx::Size size(GetSizeForClientSize(client_bounds.size()));
145 return bubble_border_->GetBounds(gfx::Rect(), size); 162 return bubble_border_->GetBounds(gfx::Rect(), size);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 title_height = std::max(title_height, title_->height()); 350 title_height = std::max(title_height, title_->height());
334 title_->SetPosition(gfx::Point( 351 title_->SetPosition(gfx::Point(
335 title_label_x, bounds.y() + (title_height - title_->height()) / 2)); 352 title_label_x, bounds.y() + (title_height - title_->height()) / 2));
336 } 353 }
337 354
338 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), 355 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(),
339 title_height); 356 title_height);
340 bounds.set_width(title_->bounds().right() - bounds.x()); 357 bounds.set_width(title_->bounds().right() - bounds.x());
341 bounds.set_height(title_height); 358 bounds.set_height(title_height);
342 359
343 if (footnote_container_) { 360 // Only account for footnote_container_'s height if it's visible, because
361 // content_margins_ adds extra padding even if all child views are invisible.
362 if (footnote_container_ && footnote_container_->visible()) {
344 const int width = contents_bounds.width(); 363 const int width = contents_bounds.width();
345 const int height = footnote_container_->GetHeightForWidth(width); 364 const int height = footnote_container_->GetHeightForWidth(width);
346 footnote_container_->SetBounds( 365 footnote_container_->SetBounds(
347 contents_bounds.x(), contents_bounds.bottom() - height, width, height); 366 contents_bounds.x(), contents_bounds.bottom() - height, width, height);
348 } 367 }
349 } 368 }
350 369
351 void BubbleFrameView::OnThemeChanged() { 370 void BubbleFrameView::OnThemeChanged() {
352 UpdateWindowTitle(); 371 UpdateWindowTitle();
353 ResetWindowControls(); 372 ResetWindowControls();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 420
402 // Update the background, which relies on the border. 421 // Update the background, which relies on the border.
403 SetBackground(base::MakeUnique<views::BubbleBackground>(bubble_border_)); 422 SetBackground(base::MakeUnique<views::BubbleBackground>(bubble_border_));
404 } 423 }
405 424
406 void BubbleFrameView::SetFootnoteView(View* view) { 425 void BubbleFrameView::SetFootnoteView(View* view) {
407 if (!view) 426 if (!view)
408 return; 427 return;
409 428
410 DCHECK(!footnote_container_); 429 DCHECK(!footnote_container_);
411 footnote_container_ = new views::View(); 430 FootnoteContainerView* footnote_container = new FootnoteContainerView();
412 footnote_container_->SetLayoutManager( 431 footnote_container->SetLayoutManager(
413 new BoxLayout(BoxLayout::kVertical, content_margins_, 0)); 432 new BoxLayout(BoxLayout::kVertical, content_margins_, 0));
414 footnote_container_->SetBackground( 433 footnote_container->SetBackground(
415 CreateSolidBackground(kFootnoteBackgroundColor)); 434 CreateSolidBackground(kFootnoteBackgroundColor));
416 footnote_container_->SetBorder( 435 footnote_container->SetBorder(
417 CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor)); 436 CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor));
418 footnote_container_->AddChildView(view); 437 footnote_container->AddChildView(view);
419 AddChildView(footnote_container_); 438 footnote_container->SetVisible(view->visible());
tapted 2017/07/10 03:52:05 Using SetVisible (rather than UpdateVisibility), m
Jared Saul 2017/07/10 19:24:40 np, done.
439 AddChildView(footnote_container);
440 footnote_container_ = footnote_container;
420 } 441 }
421 442
422 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, 443 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect,
423 const gfx::Size& client_size, 444 const gfx::Size& client_size,
424 bool adjust_if_offscreen) { 445 bool adjust_if_offscreen) {
425 gfx::Size size(GetSizeForClientSize(client_size)); 446 gfx::Size size(GetSizeForClientSize(client_size));
426 447
427 const BubbleBorder::Arrow arrow = bubble_border_->arrow(); 448 const BubbleBorder::Arrow arrow = bubble_border_->arrow();
428 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) { 449 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) {
429 // Try to mirror the anchoring if the bubble does not fit on the screen. 450 // Try to mirror the anchoring if the bubble does not fit on the screen.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 title_bar_width += title_margins_.left(); 555 title_bar_width += title_margins_.left();
535 title_bar_width += title_icon_size.width(); 556 title_bar_width += title_icon_size.width();
536 if (close_->visible()) 557 if (close_->visible())
537 title_bar_width += close_->width() + 1; 558 title_bar_width += close_->width() + 1;
538 559
539 gfx::Size size(client_size); 560 gfx::Size size(client_size);
540 gfx::Insets client_insets = GetInsets(); 561 gfx::Insets client_insets = GetInsets();
541 size.Enlarge(client_insets.width(), client_insets.height()); 562 size.Enlarge(client_insets.width(), client_insets.height());
542 size.SetToMax(gfx::Size(title_bar_width, 0)); 563 size.SetToMax(gfx::Size(title_bar_width, 0));
543 564
544 if (footnote_container_) 565 // Only account for footnote_container_'s height if it's visible, because
566 // content_margins_ adds extra padding even if all child views are invisible.
567 if (footnote_container_ && footnote_container_->visible())
545 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); 568 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width()));
546 569
547 DialogDelegate* dialog_delegate = 570 DialogDelegate* dialog_delegate =
548 GetWidget()->widget_delegate()->AsDialogDelegate(); 571 GetWidget()->widget_delegate()->AsDialogDelegate();
549 if (dialog_delegate && dialog_delegate->ShouldSnapFrameWidth()) 572 if (dialog_delegate && dialog_delegate->ShouldSnapFrameWidth())
550 size.set_width(LayoutProvider::Get()->GetSnappedDialogWidth(size.width())); 573 size.set_width(LayoutProvider::Get()->GetSnappedDialogWidth(size.width()));
551 574
552 return size; 575 return size;
553 } 576 }
554 577
555 } // namespace views 578 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698