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 | 8 |
| 9 #include "base/bind.h" |
9 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
10 #include "ui/base/hit_test.h" | 11 #include "ui/base/hit_test.h" |
11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/path.h" | 13 #include "ui/gfx/path.h" |
13 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
14 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
15 #include "ui/native_theme/native_theme.h" | 16 #include "ui/native_theme/native_theme.h" |
16 #include "ui/views/bubble/bubble_border.h" | 17 #include "ui/views/bubble/bubble_border.h" |
17 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 gfx::Insets BubbleFrameView::GetTitleInsets() { | 62 gfx::Insets BubbleFrameView::GetTitleInsets() { |
62 return gfx::Insets(kTitleTopInset, kTitleLeftInset, | 63 return gfx::Insets(kTitleTopInset, kTitleLeftInset, |
63 kTitleBottomInset, kTitleRightInset); | 64 kTitleBottomInset, kTitleRightInset); |
64 } | 65 } |
65 | 66 |
66 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins) | 67 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins) |
67 : bubble_border_(NULL), | 68 : bubble_border_(NULL), |
68 content_margins_(content_margins), | 69 content_margins_(content_margins), |
69 title_(NULL), | 70 title_(NULL), |
70 close_(NULL), | 71 close_(NULL), |
71 titlebar_extra_view_(NULL) { | 72 titlebar_extra_view_(NULL), |
| 73 before_close_callback_(base::Closure()) { |
72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 74 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
73 title_ = new Label(base::string16(), | 75 title_ = new Label(base::string16(), |
74 rb.GetFontList(ui::ResourceBundle::MediumFont)); | 76 rb.GetFontList(ui::ResourceBundle::MediumFont)); |
75 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 77 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
76 AddChildView(title_); | 78 AddChildView(title_); |
77 | 79 |
78 close_ = new LabelButton(this, base::string16()); | 80 close_ = new LabelButton(this, base::string16()); |
79 close_->SetImage(CustomButton::STATE_NORMAL, | 81 close_->SetImage(CustomButton::STATE_NORMAL, |
80 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); | 82 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); |
81 close_->SetImage(CustomButton::STATE_HOVERED, | 83 close_->SetImage(CustomButton::STATE_HOVERED, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 233 |
232 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 234 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
233 if (bubble_border_ && bubble_border_->use_theme_background_color()) { | 235 if (bubble_border_ && bubble_border_->use_theme_background_color()) { |
234 bubble_border_->set_background_color(GetNativeTheme()-> | 236 bubble_border_->set_background_color(GetNativeTheme()-> |
235 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)); | 237 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)); |
236 SchedulePaint(); | 238 SchedulePaint(); |
237 } | 239 } |
238 } | 240 } |
239 | 241 |
240 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) { | 242 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) { |
241 if (sender == close_) | 243 if (sender == close_) { |
| 244 if (!before_close_callback_.is_null()) |
| 245 before_close_callback_.Run(); |
242 GetWidget()->Close(); | 246 GetWidget()->Close(); |
| 247 } |
243 } | 248 } |
244 | 249 |
245 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) { | 250 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) { |
246 bubble_border_ = border.get(); | 251 bubble_border_ = border.get(); |
247 SetBorder(border.PassAs<Border>()); | 252 SetBorder(border.PassAs<Border>()); |
248 | 253 |
249 // Update the background, which relies on the border. | 254 // Update the background, which relies on the border. |
250 set_background(new views::BubbleBackground(bubble_border_)); | 255 set_background(new views::BubbleBackground(bubble_border_)); |
251 } | 256 } |
252 | 257 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 if (titlebar_extra_view_ != NULL) | 366 if (titlebar_extra_view_ != NULL) |
362 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); | 367 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); |
363 gfx::Size size(client_size); | 368 gfx::Size size(client_size); |
364 size.SetToMax(gfx::Size(title_bar_width, 0)); | 369 size.SetToMax(gfx::Size(title_bar_width, 0)); |
365 const gfx::Insets insets(GetInsets()); | 370 const gfx::Insets insets(GetInsets()); |
366 size.Enlarge(insets.width(), insets.height()); | 371 size.Enlarge(insets.width(), insets.height()); |
367 return size; | 372 return size; |
368 } | 373 } |
369 | 374 |
370 } // namespace views | 375 } // namespace views |
OLD | NEW |