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

Side by Side Diff: ui/views/window/dialog_frame_view.cc

Issue 11571023: Move ash/wm's DialogFrameView to ui/views/window; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove redundant GetContentsView() OVERRIDEs; re-git-add dialog_frame_view files. Created 8 years 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 | Annotate | Revision Log
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 "ash/wm/dialog_frame_view.h" 5 #include "ui/views/window/dialog_frame_view.h"
6 6
7 #include "grit/ui_resources.h" 7 #include "grit/ui_resources.h"
8 #include "ui/base/hit_test.h" 8 #include "ui/base/hit_test.h"
9 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/font.h" 11 #include "ui/gfx/font.h"
12 #include "ui/gfx/image/image.h" 12 #include "ui/gfx/image/image.h"
13 #include "ui/gfx/insets.h" 13 #include "ui/gfx/insets.h"
14 #include "ui/views/background.h" 14 #include "ui/views/background.h"
15 #include "ui/views/border.h" 15 #include "ui/views/border.h"
(...skipping 26 matching lines...) Expand all
42 const int kDialogTopPaddingNudge = 5; 42 const int kDialogTopPaddingNudge = 5;
43 const int kDialogBottomPaddingNudge = 10; 43 const int kDialogBottomPaddingNudge = 10;
44 44
45 // TODO(benrg): There are no examples in the spec of close boxes on medium- or 45 // TODO(benrg): There are no examples in the spec of close boxes on medium- or
46 // small-size dialogs, and the close button size is not factored into other 46 // small-size dialogs, and the close button size is not factored into other
47 // sizing decisions. This value could cause problems with smaller dialogs. 47 // sizing decisions. This value could cause problems with smaller dialogs.
48 const int kCloseButtonSize = 44; 48 const int kCloseButtonSize = 44;
49 49
50 } // namespace 50 } // namespace
51 51
52 namespace ash { 52 namespace views {
53 namespace internal {
54 53
55 // static 54 // static
56 const char DialogFrameView::kViewClassName[] = "ash/wm/DialogFrameView"; 55 const char DialogFrameView::kViewClassName[] = "ui/views/DialogFrameView";
57 56
58 //////////////////////////////////////////////////////////////////////////////// 57 ////////////////////////////////////////////////////////////////////////////////
59 // DialogFrameView, public: 58 // DialogFrameView, public:
60 59
61 DialogFrameView::DialogFrameView() { 60 DialogFrameView::DialogFrameView() {
62 set_background(views::Background::CreateSolidBackground( 61 set_background(Background::CreateSolidBackground(kDialogBackgroundColor));
63 kDialogBackgroundColor));
64 62
65 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
66 title_font_.reset(new gfx::Font(rb.GetFont(ui::ResourceBundle::MediumFont))); 64 title_font_.reset(new gfx::Font(rb.GetFont(ui::ResourceBundle::MediumFont)));
67 close_button_ = new views::ImageButton(this); 65 close_button_ = new views::ImageButton(this);
68 close_button_->SetImage(views::CustomButton::STATE_NORMAL, 66 close_button_->SetImage(views::CustomButton::STATE_NORMAL,
69 rb.GetImageNamed(IDR_CLOSE_BAR).ToImageSkia()); 67 rb.GetImageNamed(IDR_CLOSE_BAR).ToImageSkia());
70 close_button_->SetImage(views::CustomButton::STATE_HOVERED, 68 close_button_->SetImage(CustomButton::STATE_HOVERED,
71 rb.GetImageNamed(IDR_CLOSE_BAR_H).ToImageSkia()); 69 rb.GetImageNamed(IDR_CLOSE_BAR_H).ToImageSkia());
72 close_button_->SetImage(views::CustomButton::STATE_PRESSED, 70 close_button_->SetImage(CustomButton::STATE_PRESSED,
73 rb.GetImageNamed(IDR_CLOSE_BAR_P).ToImageSkia()); 71 rb.GetImageNamed(IDR_CLOSE_BAR_P).ToImageSkia());
74 close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, 72 close_button_->SetImageAlignment(ImageButton::ALIGN_CENTER,
75 views::ImageButton::ALIGN_MIDDLE); 73 ImageButton::ALIGN_MIDDLE);
76 AddChildView(close_button_); 74 AddChildView(close_button_);
77 } 75 }
78 76
79 DialogFrameView::~DialogFrameView() { 77 DialogFrameView::~DialogFrameView() {
80 } 78 }
81 79
82 //////////////////////////////////////////////////////////////////////////////// 80 ////////////////////////////////////////////////////////////////////////////////
83 // DialogFrameView, views::NonClientFrameView: 81 // DialogFrameView, NonClientFrameView:
84 82
85 gfx::Rect DialogFrameView::GetBoundsForClientView() const { 83 gfx::Rect DialogFrameView::GetBoundsForClientView() const {
86 gfx::Rect client_bounds = GetLocalBounds(); 84 gfx::Rect client_bounds = GetLocalBounds();
87 client_bounds.Inset(GetClientInsets()); 85 client_bounds.Inset(GetClientInsets());
88 return client_bounds; 86 return client_bounds;
89 } 87 }
90 88
91 gfx::Rect DialogFrameView::GetWindowBoundsForClientBounds( 89 gfx::Rect DialogFrameView::GetWindowBoundsForClientBounds(
92 const gfx::Rect& client_bounds) const { 90 const gfx::Rect& client_bounds) const {
93 gfx::Rect window_bounds = client_bounds; 91 gfx::Rect window_bounds = client_bounds;
(...skipping 18 matching lines...) Expand all
112 110
113 void DialogFrameView::UpdateWindowIcon() { 111 void DialogFrameView::UpdateWindowIcon() {
114 // Nothing to do. 112 // Nothing to do.
115 } 113 }
116 114
117 void DialogFrameView::UpdateWindowTitle() { 115 void DialogFrameView::UpdateWindowTitle() {
118 // Nothing to do. 116 // Nothing to do.
119 } 117 }
120 118
121 //////////////////////////////////////////////////////////////////////////////// 119 ////////////////////////////////////////////////////////////////////////////////
122 // DialogFrameView, views::View overrides: 120 // DialogFrameView, View overrides:
123 121
124 std::string DialogFrameView::GetClassName() const { 122 std::string DialogFrameView::GetClassName() const {
125 return kViewClassName; 123 return kViewClassName;
126 } 124 }
127 125
128 void DialogFrameView::Layout() { 126 void DialogFrameView::Layout() {
129 title_display_rect_ = GetLocalBounds(); 127 title_display_rect_ = GetLocalBounds();
130 title_display_rect_.Inset(GetPaddingInsets()); 128 title_display_rect_.Inset(GetPaddingInsets());
131 title_display_rect_.set_height(title_font_->GetHeight()); 129 title_display_rect_.set_height(title_font_->GetHeight());
132 130
133 // The hot rectangle for the close button is flush with the upper right of the 131 // The hot rectangle for the close button is flush with the upper right of the
134 // dialog. The close button image is smaller, and is centered in the hot rect. 132 // dialog. The close button image is smaller, and is centered in the hot rect.
135 close_button_->SetBounds( 133 close_button_->SetBounds(
136 width() - kCloseButtonSize, 134 width() - kCloseButtonSize,
137 0, kCloseButtonSize, kCloseButtonSize); 135 0, kCloseButtonSize, kCloseButtonSize);
138 } 136 }
139 137
140 void DialogFrameView::OnPaint(gfx::Canvas* canvas) { 138 void DialogFrameView::OnPaint(gfx::Canvas* canvas) {
141 views::View::OnPaint(canvas); 139 View::OnPaint(canvas);
142 views::WidgetDelegate* delegate = GetWidget()->widget_delegate(); 140 WidgetDelegate* delegate = GetWidget()->widget_delegate();
143 if (!delegate) 141 if (!delegate)
144 return; 142 return;
145 canvas->DrawStringInt(delegate->GetWindowTitle(), *title_font_.get(), 143 canvas->DrawStringInt(delegate->GetWindowTitle(), *title_font_.get(),
146 kDialogTitleColor, title_display_rect_); 144 kDialogTitleColor, title_display_rect_);
147 } 145 }
148 146
149 //////////////////////////////////////////////////////////////////////////////// 147 ////////////////////////////////////////////////////////////////////////////////
150 // DialogFrameView, views::ButtonListener overrides: 148 // DialogFrameView, ButtonListener overrides:
151 149
152 void DialogFrameView::ButtonPressed(views::Button* sender, 150 void DialogFrameView::ButtonPressed(Button* sender, const ui::Event& event) {
153 const ui::Event& event) {
154 if (sender == close_button_) 151 if (sender == close_button_)
155 GetWidget()->Close(); 152 GetWidget()->Close();
156 } 153 }
157 154
158 //////////////////////////////////////////////////////////////////////////////// 155 ////////////////////////////////////////////////////////////////////////////////
159 // DialogFrameView, private: 156 // DialogFrameView, private:
160 157
161 gfx::Insets DialogFrameView::GetPaddingInsets() const { 158 gfx::Insets DialogFrameView::GetPaddingInsets() const {
162 // These three discrete padding sizes come from the spec. If we ever wanted 159 // These three discrete padding sizes come from the spec. If we ever wanted
163 // our Google-style dialogs to be resizable, we would probably need to 160 // our Google-style dialogs to be resizable, we would probably need to
(...skipping 18 matching lines...) Expand all
182 // and one em is equal to the font size (CSS spec). 179 // and one em is equal to the font size (CSS spec).
183 insets += gfx::Insets( 180 insets += gfx::Insets(
184 title_font_->GetHeight() + title_font_->GetFontSize() - 181 title_font_->GetHeight() + title_font_->GetFontSize() -
185 kDialogTopPaddingNudge, 182 kDialogTopPaddingNudge,
186 -kDialogHPaddingNudge, 183 -kDialogHPaddingNudge,
187 -kDialogBottomPaddingNudge, 184 -kDialogBottomPaddingNudge,
188 -kDialogHPaddingNudge); 185 -kDialogHPaddingNudge);
189 return insets; 186 return insets;
190 } 187 }
191 188
192 } // namespace internal
193 } // namespace views 189 } // namespace views
OLDNEW
« ui/views/window/dialog_delegate.h ('K') | « ui/views/window/dialog_frame_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698