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

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

Issue 1849703004: Handle bubble title resizing (growth) by reworking title layout (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweaks Created 4 years, 8 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 17 matching lines...) Expand all
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 gfx::Rect bounds(GetContentsBounds()); 292 gfx::Rect bounds(GetContentsBounds());
296 bounds.Inset(title_margins_); 293 bounds.Inset(title_margins_);
297 if (bounds.IsEmpty()) 294 if (bounds.IsEmpty())
298 return; 295 return;
299 296
300 // The close button is positioned somewhat closer to the edge of the bubble. 297 // The close button is positioned somewhat closer to the edge of the bubble.
301 gfx::Point close_position = GetContentsBounds().top_right(); 298 gfx::Point close_position = GetContentsBounds().top_right();
302 close_position += gfx::Vector2d(-close_->width() - 7, 6); 299 close_position += gfx::Vector2d(-close_->width() - 7, 6);
303 close_->SetPosition(close_position); 300 close_->SetPosition(close_position);
304 301
305 gfx::Size title_icon_size(title_icon_->GetPreferredSize()); 302 gfx::Size title_icon_pref_size(title_icon_->GetPreferredSize());
306 gfx::Size title_label_size(title_->GetPreferredSize());
307 int padding = 0; 303 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 304
313 const int title_icon_width = std::max(0, close_->x() - bounds.x()); 305 if (!title_->text().empty()) {
msw 2016/03/31 19:18:31 Some WidgetDelegate may return a non-empty GetWind
msw 2016/03/31 21:28:27 Ping
Evan Stade 2016/03/31 22:07:06 Done. Good catch.
314 title_icon_size.SetToMin(gfx::Size(title_icon_width, title_height)); 306 if (title_icon_pref_size.width() > 0)
315 gfx::Rect title_icon_bounds( 307 padding = title_margins_.left();
msw 2016/03/31 19:18:31 Hmm, re-using the title margins (for outside the i
Evan Stade 2016/03/31 21:26:13 This screenshot captures both visual improvements/
316 bounds.x(), bounds.y(), title_icon_size.width(), title_height);
317 title_icon_->SetBoundsRect(title_icon_bounds);
318 308
319 const int title_label_x = title_icon_->bounds().right() + padding; 309 const int title_label_x =
320 const int title_label_width = std::max(0, close_->x() - title_label_x); 310 bounds.x() + title_icon_pref_size.width() + padding;
321 title_label_size.SetToMin(gfx::Size(title_label_width, 311 title_->SizeToFit(std::max(1, close_->x() - title_label_x));
msw 2016/03/31 19:18:31 q: why 1 over 0? (for my enlightenment)
Evan Stade 2016/03/31 21:26:13 because I'm afraid of crazy things like infinite l
322 title_label_size.height())); 312 title_->SetPosition(gfx::Point(title_label_x, bounds.y()));
323 gfx::Rect title_label_bounds( 313 }
324 title_label_x, bounds.y(), title_label_size.width(), title_height);
325 title_->SetBoundsRect(title_label_bounds);
326 314
327 bounds.set_width( 315 const int title_height =
328 title_icon_size.width() + title_label_size.width() + padding); 316 std::max(title_icon_pref_size.height(), title_->height());
317 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(),
318 title_height);
319 bounds.set_width(title_->bounds().right() - title_icon_->x());
msw 2016/03/31 19:18:31 nit: use bounds.x() instead of title_icon_->x()?
Evan Stade 2016/03/31 21:26:13 Done.
329 bounds.set_height(title_height); 320 bounds.set_height(title_height);
330 321
331 if (footnote_container_) { 322 if (footnote_container_) {
332 gfx::Rect local_bounds = GetContentsBounds(); 323 gfx::Rect local_bounds = GetContentsBounds();
333 int height = footnote_container_->GetHeightForWidth(local_bounds.width()); 324 int height = footnote_container_->GetHeightForWidth(local_bounds.width());
334 footnote_container_->SetBounds(local_bounds.x(), 325 footnote_container_->SetBounds(local_bounds.x(),
335 local_bounds.bottom() - height, 326 local_bounds.bottom() - height,
336 local_bounds.width(), height); 327 local_bounds.width(), height);
337 } 328 }
338 } 329 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 SchedulePaint(); 492 SchedulePaint();
502 } 493 }
503 494
504 gfx::Size BubbleFrameView::GetSizeForClientSize( 495 gfx::Size BubbleFrameView::GetSizeForClientSize(
505 const gfx::Size& client_size) const { 496 const gfx::Size& client_size) const {
506 // Accommodate the width of the title bar elements. 497 // Accommodate the width of the title bar elements.
507 int title_bar_width = title_margins_.width() + border()->GetInsets().width(); 498 int title_bar_width = title_margins_.width() + border()->GetInsets().width();
508 gfx::Size title_icon_size = title_icon_->GetPreferredSize(); 499 gfx::Size title_icon_size = title_icon_->GetPreferredSize();
509 gfx::Size title_label_size = title_->GetPreferredSize(); 500 gfx::Size title_label_size = title_->GetPreferredSize();
510 if (title_icon_size.width() > 0 && title_label_size.width() > 0) 501 if (title_icon_size.width() > 0 && title_label_size.width() > 0)
511 title_bar_width += kTitleHorizontalPadding; 502 title_bar_width += title_margins_.left();
512 title_bar_width += title_icon_size.width(); 503 title_bar_width += title_icon_size.width();
513 if (close_->visible()) 504 if (close_->visible())
514 title_bar_width += close_->width() + 1; 505 title_bar_width += close_->width() + 1;
515 506
516 gfx::Size size(client_size); 507 gfx::Size size(client_size);
517 gfx::Insets client_insets = GetInsets(); 508 gfx::Insets client_insets = GetInsets();
518 size.Enlarge(client_insets.width(), client_insets.height()); 509 size.Enlarge(client_insets.width(), client_insets.height());
519 size.SetToMax(gfx::Size(title_bar_width, 0)); 510 size.SetToMax(gfx::Size(title_bar_width, 0));
520 511
521 if (footnote_container_) 512 if (footnote_container_)
522 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); 513 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width()));
523 514
524 return size; 515 return size;
525 } 516 }
526 517
527 } // namespace views 518 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698