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