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

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

Issue 341823005: Collects stats on how user interacts with the bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 6 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 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 24 matching lines...) Expand all
43 // | +------------------+ | 44 // | +------------------+ |
44 // | bottom | 45 // | bottom |
45 // +---------------------------------+ 46 // +---------------------------------+
46 if (vertical) 47 if (vertical)
47 return std::max(0, available_bounds.y() - window_bounds.y()) + 48 return std::max(0, available_bounds.y() - window_bounds.y()) +
48 std::max(0, window_bounds.bottom() - available_bounds.bottom()); 49 std::max(0, window_bounds.bottom() - available_bounds.bottom());
49 return std::max(0, available_bounds.x() - window_bounds.x()) + 50 return std::max(0, available_bounds.x() - window_bounds.x()) +
50 std::max(0, window_bounds.right() - available_bounds.right()); 51 std::max(0, window_bounds.right() - available_bounds.right());
51 } 52 }
52 53
54 // The default value for callback_before_close_.
55 void EmptyCallback() {}
56
53 } // namespace 57 } // namespace
54 58
55 namespace views { 59 namespace views {
56 60
57 // static 61 // static
58 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; 62 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView";
59 63
60 // static 64 // static
61 gfx::Insets BubbleFrameView::GetTitleInsets() { 65 gfx::Insets BubbleFrameView::GetTitleInsets() {
62 return gfx::Insets(kTitleTopInset, kTitleLeftInset, 66 return gfx::Insets(kTitleTopInset, kTitleLeftInset,
63 kTitleBottomInset, kTitleRightInset); 67 kTitleBottomInset, kTitleRightInset);
64 } 68 }
65 69
66 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins) 70 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins)
67 : bubble_border_(NULL), 71 : bubble_border_(NULL),
68 content_margins_(content_margins), 72 content_margins_(content_margins),
69 title_(NULL), 73 title_(NULL),
70 close_(NULL), 74 close_(NULL),
71 titlebar_extra_view_(NULL) { 75 titlebar_extra_view_(NULL),
76 callback_before_close_(base::Bind(&EmptyCallback)) {
Alexei Svitkine (slow) 2014/07/02 15:07:26 I think you can initialize it with the default cto
yao 2014/07/07 17:47:45 Done.
72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 77 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
73 title_ = new Label(base::string16(), 78 title_ = new Label(base::string16(),
74 rb.GetFontList(ui::ResourceBundle::MediumFont)); 79 rb.GetFontList(ui::ResourceBundle::MediumFont));
75 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 80 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
76 AddChildView(title_); 81 AddChildView(title_);
77 82
78 close_ = new LabelButton(this, base::string16()); 83 close_ = new LabelButton(this, base::string16());
79 close_->SetImage(CustomButton::STATE_NORMAL, 84 close_->SetImage(CustomButton::STATE_NORMAL,
80 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); 85 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia());
81 close_->SetImage(CustomButton::STATE_HOVERED, 86 close_->SetImage(CustomButton::STATE_HOVERED,
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 236
232 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 237 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
233 if (bubble_border_ && bubble_border_->use_theme_background_color()) { 238 if (bubble_border_ && bubble_border_->use_theme_background_color()) {
234 bubble_border_->set_background_color(GetNativeTheme()-> 239 bubble_border_->set_background_color(GetNativeTheme()->
235 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground)); 240 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground));
236 SchedulePaint(); 241 SchedulePaint();
237 } 242 }
238 } 243 }
239 244
240 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) { 245 void BubbleFrameView::ButtonPressed(Button* sender, const ui::Event& event) {
241 if (sender == close_) 246 if (sender == close_) {
247 callback_before_close_.Run();
242 GetWidget()->Close(); 248 GetWidget()->Close();
249 }
243 } 250 }
244 251
245 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) { 252 void BubbleFrameView::SetBubbleBorder(scoped_ptr<BubbleBorder> border) {
246 bubble_border_ = border.get(); 253 bubble_border_ = border.get();
247 SetBorder(border.PassAs<Border>()); 254 SetBorder(border.PassAs<Border>());
248 255
249 // Update the background, which relies on the border. 256 // Update the background, which relies on the border.
250 set_background(new views::BubbleBackground(bubble_border_)); 257 set_background(new views::BubbleBackground(bubble_border_));
251 } 258 }
252 259
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 if (titlebar_extra_view_ != NULL) 368 if (titlebar_extra_view_ != NULL)
362 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); 369 title_bar_width += titlebar_extra_view_->GetPreferredSize().width();
363 gfx::Size size(client_size); 370 gfx::Size size(client_size);
364 size.SetToMax(gfx::Size(title_bar_width, 0)); 371 size.SetToMax(gfx::Size(title_bar_width, 0));
365 const gfx::Insets insets(GetInsets()); 372 const gfx::Insets insets(GetInsets());
366 size.Enlarge(insets.width(), insets.height()); 373 size.Enlarge(insets.width(), insets.height());
367 return size; 374 return size;
368 } 375 }
369 376
370 } // namespace views 377 } // namespace views
OLDNEW
« ui/views/bubble/bubble_frame_view.h ('K') | « ui/views/bubble/bubble_frame_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698