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

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

Issue 1717453003: Introduce BubbleDialogDelegateView, which extends DialogDelegateView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: relative ps Created 4 years, 10 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; 70 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView";
71 71
72 BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins, 72 BubbleFrameView::BubbleFrameView(const gfx::Insets& title_margins,
73 const gfx::Insets& content_margins) 73 const gfx::Insets& content_margins)
74 : bubble_border_(nullptr), 74 : bubble_border_(nullptr),
75 title_margins_(title_margins), 75 title_margins_(title_margins),
76 content_margins_(content_margins), 76 content_margins_(content_margins),
77 title_icon_(new views::ImageView()), 77 title_icon_(new views::ImageView()),
78 title_(nullptr), 78 title_(nullptr),
79 close_(nullptr), 79 close_(nullptr),
80 titlebar_extra_view_(nullptr),
81 footnote_container_(nullptr), 80 footnote_container_(nullptr),
82 close_button_clicked_(false) { 81 close_button_clicked_(false) {
83 AddChildView(title_icon_); 82 AddChildView(title_icon_);
84 83
85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 84 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
86 title_ = new Label(base::string16(), 85 title_ = new Label(base::string16(),
87 rb.GetFontList(ui::ResourceBundle::MediumFont)); 86 rb.GetFontList(ui::ResourceBundle::MediumFont));
88 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 87 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
89 title_->set_collapse_when_hidden(true); 88 title_->set_collapse_when_hidden(true);
90 title_->SetVisible(false); 89 title_->SetVisible(false);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 title_label_size.SetToMin(gfx::Size(title_label_width, 299 title_label_size.SetToMin(gfx::Size(title_label_width,
301 title_label_size.height())); 300 title_label_size.height()));
302 gfx::Rect title_label_bounds( 301 gfx::Rect title_label_bounds(
303 title_label_x, bounds.y(), title_label_size.width(), title_height); 302 title_label_x, bounds.y(), title_label_size.width(), title_height);
304 title_->SetBoundsRect(title_label_bounds); 303 title_->SetBoundsRect(title_label_bounds);
305 304
306 bounds.set_width( 305 bounds.set_width(
307 title_icon_size.width() + title_label_size.width() + padding); 306 title_icon_size.width() + title_label_size.width() + padding);
308 bounds.set_height(title_height); 307 bounds.set_height(title_height);
309 308
310 if (titlebar_extra_view_) {
311 const int extra_width = close_->x() - bounds.right();
312 gfx::Size size = titlebar_extra_view_->GetPreferredSize();
313 size.SetToMin(gfx::Size(std::max(0, extra_width), size.height()));
314 gfx::Rect titlebar_extra_view_bounds(
315 close_->x() - size.width(),
316 bounds.y(),
317 size.width(),
318 bounds.height());
319 titlebar_extra_view_bounds.Subtract(bounds);
320 titlebar_extra_view_->SetBoundsRect(titlebar_extra_view_bounds);
321 }
322
323 if (footnote_container_) { 309 if (footnote_container_) {
324 gfx::Rect local_bounds = GetContentsBounds(); 310 gfx::Rect local_bounds = GetContentsBounds();
325 int height = footnote_container_->GetHeightForWidth(local_bounds.width()); 311 int height = footnote_container_->GetHeightForWidth(local_bounds.width());
326 footnote_container_->SetBounds(local_bounds.x(), 312 footnote_container_->SetBounds(local_bounds.x(),
327 local_bounds.bottom() - height, 313 local_bounds.bottom() - height,
328 local_bounds.width(), height); 314 local_bounds.width(), height);
329 } 315 }
330 } 316 }
331 317
332 const char* BubbleFrameView::GetClassName() const { 318 const char* BubbleFrameView::GetClassName() const {
333 return kViewClassName; 319 return kViewClassName;
334 } 320 }
335 321
336 void BubbleFrameView::ChildPreferredSizeChanged(View* child) {
337 if (child == titlebar_extra_view_ || child == title_)
338 Layout();
339 }
340
341 void BubbleFrameView::OnThemeChanged() { 322 void BubbleFrameView::OnThemeChanged() {
342 UpdateWindowTitle(); 323 UpdateWindowTitle();
343 ResetWindowControls(); 324 ResetWindowControls();
344 UpdateWindowIcon(); 325 UpdateWindowIcon();
345 } 326 }
346 327
347 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 328 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
348 if (bubble_border_ && bubble_border_->use_theme_background_color()) { 329 if (bubble_border_ && bubble_border_->use_theme_background_color()) {
349 bubble_border_->set_background_color(GetNativeTheme()-> 330 bubble_border_->set_background_color(GetNativeTheme()->
350 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)); 331 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground));
351 SchedulePaint(); 332 SchedulePaint();
352 } 333 }
353 } 334 }
354 335
355 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) { 336 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) {
356 if (sender == close_) { 337 if (sender == close_) {
357 close_button_clicked_ = true; 338 close_button_clicked_ = true;
358 GetWidget()->Close(); 339 GetWidget()->Close();
359 } 340 }
360 } 341 }
361 342
362 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) { 343 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) {
363 bubble_border_ = border.get(); 344 bubble_border_ = border.get();
364 SetBorder(std::move(border)); 345 SetBorder(std::move(border));
365 346
366 // Update the background, which relies on the border. 347 // Update the background, which relies on the border.
367 set_background(new views::BubbleBackground(bubble_border_)); 348 set_background(new views::BubbleBackground(bubble_border_));
368 } 349 }
369 350
370 void BubbleFrameView::SetTitlebarExtraView(scoped_ptr<View> view) { 351 void BubbleFrameView::SetFootnoteView(View* view) {
371 if (!view)
372 return;
373
374 DCHECK(!titlebar_extra_view_);
375 titlebar_extra_view_ = view.release();
376 AddChildView(titlebar_extra_view_);
377 }
378
379 void BubbleFrameView::SetFootnoteView(scoped_ptr<View> view) {
380 if (!view) 352 if (!view)
381 return; 353 return;
382 354
383 DCHECK(!footnote_container_); 355 DCHECK(!footnote_container_);
384
385 footnote_container_ = new views::View(); 356 footnote_container_ = new views::View();
386 footnote_container_->SetLayoutManager( 357 footnote_container_->SetLayoutManager(
387 new BoxLayout(BoxLayout::kVertical, content_margins_.left(), 358 new BoxLayout(BoxLayout::kVertical, content_margins_.left(),
388 content_margins_.top(), 0)); 359 content_margins_.top(), 0));
389 footnote_container_->set_background( 360 footnote_container_->set_background(
390 Background::CreateSolidBackground(kFootnoteBackgroundColor)); 361 Background::CreateSolidBackground(kFootnoteBackgroundColor));
391 footnote_container_->SetBorder( 362 footnote_container_->SetBorder(
392 Border::CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor)); 363 Border::CreateSolidSidedBorder(1, 0, 0, 0, kFootnoteBorderColor));
393 footnote_container_->AddChildView(view.release()); 364 footnote_container_->AddChildView(view);
394 AddChildView(footnote_container_); 365 AddChildView(footnote_container_);
395 } 366 }
396 367
397 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect, 368 gfx::Rect BubbleFrameView::GetUpdatedWindowBounds(const gfx::Rect& anchor_rect,
398 gfx::Size client_size, 369 gfx::Size client_size,
399 bool adjust_if_offscreen) { 370 bool adjust_if_offscreen) {
400 gfx::Size size(GetSizeForClientSize(client_size)); 371 gfx::Size size(GetSizeForClientSize(client_size));
401 372
402 const BubbleBorder::Arrow arrow = bubble_border_->arrow(); 373 const BubbleBorder::Arrow arrow = bubble_border_->arrow();
403 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) { 374 if (adjust_if_offscreen && BubbleBorder::has_arrow(arrow)) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 const gfx::Size& client_size) const { 474 const gfx::Size& client_size) const {
504 // Accommodate the width of the title bar elements. 475 // Accommodate the width of the title bar elements.
505 int title_bar_width = title_margins_.width() + border()->GetInsets().width(); 476 int title_bar_width = title_margins_.width() + border()->GetInsets().width();
506 gfx::Size title_icon_size = title_icon_->GetPreferredSize(); 477 gfx::Size title_icon_size = title_icon_->GetPreferredSize();
507 gfx::Size title_label_size = title_->GetPreferredSize(); 478 gfx::Size title_label_size = title_->GetPreferredSize();
508 if (title_icon_size.width() > 0 && title_label_size.width() > 0) 479 if (title_icon_size.width() > 0 && title_label_size.width() > 0)
509 title_bar_width += kTitleHorizontalPadding; 480 title_bar_width += kTitleHorizontalPadding;
510 title_bar_width += title_icon_size.width(); 481 title_bar_width += title_icon_size.width();
511 if (close_->visible()) 482 if (close_->visible())
512 title_bar_width += close_->width() + 1; 483 title_bar_width += close_->width() + 1;
513 if (titlebar_extra_view_)
514 title_bar_width += titlebar_extra_view_->GetPreferredSize().width();
515 484
516 gfx::Size size(client_size); 485 gfx::Size size(client_size);
517 gfx::Insets client_insets = GetInsets(); 486 gfx::Insets client_insets = GetInsets();
518 size.Enlarge(client_insets.width(), client_insets.height()); 487 size.Enlarge(client_insets.width(), client_insets.height());
519 size.SetToMax(gfx::Size(title_bar_width, 0)); 488 size.SetToMax(gfx::Size(title_bar_width, 0));
520 489
521 if (footnote_container_) 490 if (footnote_container_)
522 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); 491 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width()));
523 492
524 return size; 493 return size;
525 } 494 }
526 495
527 } // namespace views 496 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698