| 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/window/dialog_client_view.h" | 5 #include "ui/views/window/dialog_client_view.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #include <uxtheme.h> | 11 #include <uxtheme.h> |
| 12 #include <vsstyle.h> | 12 #include <vsstyle.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 | 16 |
| 17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 18 #include "grit/ui_strings.h" | 18 #include "grit/ui_strings.h" |
| 19 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
| 20 #include "ui/base/keycodes/keyboard_codes.h" | 20 #include "ui/base/keycodes/keyboard_codes.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/native_theme/native_theme.h" | 22 #include "ui/base/native_theme/native_theme.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 25 #include "ui/gfx/font.h" | 25 #include "ui/gfx/font.h" |
| 26 #include "ui/views/controls/button/text_button.h" | 26 #include "ui/views/controls/button/text_button.h" |
| 27 #include "ui/views/controls/button/chrome_style.h" |
| 27 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
| 28 #include "ui/views/widget/root_view.h" | 29 #include "ui/views/widget/root_view.h" |
| 29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 30 #include "ui/views/window/dialog_delegate.h" | 31 #include "ui/views/window/dialog_delegate.h" |
| 31 | 32 |
| 32 namespace views { | 33 namespace views { |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 const int kDialogMinButtonWidth = 75; | 36 const int kDialogMinButtonWidth = 75; |
| 36 const int kDialogButtonLabelSpacing = 16; | 37 const int kDialogButtonLabelSpacing = 16; |
| 37 const int kDialogButtonContentSpacing = 5; | 38 const int kDialogButtonContentSpacing = 5; |
| 38 | 39 |
| 39 // The group used by the buttons. This name is chosen voluntarily big not to | 40 // The group used by the buttons. This name is chosen voluntarily big not to |
| 40 // conflict with other groups that could be in the dialog content. | 41 // conflict with other groups that could be in the dialog content. |
| 41 const int kButtonGroup = 6666; | 42 const int kButtonGroup = 6666; |
| 42 | 43 |
| 43 const gfx::Font& GetDialogButtonFont() { | 44 const gfx::Font& GetDialogButtonFont() { |
| 44 static gfx::Font* font = NULL; | 45 static gfx::Font* font = NULL; |
| 45 if (!font) { | 46 if (!font) { |
| 46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 47 font = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); | 48 font = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); |
| 48 } | 49 } |
| 49 return *font; | 50 return *font; |
| 50 } | 51 } |
| 51 | 52 |
| 52 // Updates any of the standard buttons according to the delegate. | 53 // Updates any of the standard buttons according to the delegate. |
| 53 void UpdateButtonHelper(NativeTextButton* button_view, | 54 void UpdateButtonHelper(TextButton* button_view, |
| 54 DialogDelegate* delegate, | 55 DialogDelegate* delegate, |
| 55 ui::DialogButton button) { | 56 ui::DialogButton button) { |
| 56 string16 label = delegate->GetDialogButtonLabel(button); | 57 string16 label = delegate->GetDialogButtonLabel(button); |
| 57 if (!label.empty()) | 58 if (!label.empty()) |
| 58 button_view->SetText(label); | 59 button_view->SetText(label); |
| 59 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); | 60 button_view->SetEnabled(delegate->IsDialogButtonEnabled(button)); |
| 60 button_view->SetVisible(delegate->IsDialogButtonVisible(button)); | 61 button_view->SetVisible(delegate->IsDialogButtonVisible(button)); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // DialogButton ---------------------------------------------------------------- | 64 // DialogButton ---------------------------------------------------------------- |
| 64 | 65 |
| 65 // DialogButtons is used for the ok/cancel buttons of the window. DialogButton | 66 // DialogButton forwards AcceleratorPressed to the delegate. It is used |
| 66 // forwards AcceleratorPressed to the delegate. | 67 // for the ok/cancel buttons of the window. |
| 67 | 68 |
| 68 class DialogButton : public NativeTextButton { | 69 template <class ButtonBase> |
| 70 class DialogButton : public ButtonBase { |
| 69 public: | 71 public: |
| 72 // The button's class name. |
| 73 static const char kViewClassName[]; |
| 74 |
| 70 DialogButton(ButtonListener* listener, | 75 DialogButton(ButtonListener* listener, |
| 71 Widget* owner, | 76 Widget* owner, |
| 72 ui::DialogButton type, | 77 ui::DialogButton type, |
| 73 const string16& title, | 78 const string16& title) |
| 74 bool is_default) | 79 : ButtonBase(listener, title), |
| 75 : NativeTextButton(listener, title), | |
| 76 owner_(owner), | 80 owner_(owner), |
| 77 type_(type) { | 81 type_(type) { |
| 78 SetIsDefault(is_default); | |
| 79 } | 82 } |
| 80 | 83 |
| 81 // Overridden to forward to the delegate. | 84 // Overridden to forward to the delegate. |
| 82 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { | 85 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 83 if (!owner_->widget_delegate()->AsDialogDelegate()-> | 86 if (!owner_->widget_delegate()->AsDialogDelegate()-> |
| 84 AreAcceleratorsEnabled(type_)) { | 87 AreAcceleratorsEnabled(type_)) { |
| 85 return false; | 88 return false; |
| 86 } | 89 } |
| 87 return NativeTextButton::AcceleratorPressed(accelerator); | 90 return ButtonBase::AcceleratorPressed(accelerator); |
| 91 } |
| 92 |
| 93 // Overridden from TextButton: |
| 94 virtual std::string GetClassName() const { |
| 95 return kViewClassName; |
| 88 } | 96 } |
| 89 | 97 |
| 90 private: | 98 private: |
| 91 Widget* owner_; | 99 Widget* owner_; |
| 92 const ui::DialogButton type_; | 100 const ui::DialogButton type_; |
| 93 | 101 |
| 94 DISALLOW_COPY_AND_ASSIGN(DialogButton); | 102 DISALLOW_COPY_AND_ASSIGN(DialogButton); |
| 95 }; | 103 }; |
| 96 | 104 |
| 105 const char DialogButton<NativeTextButton>::kViewClassName[] = |
| 106 "NativeDialogButton"; |
| 107 |
| 108 const char DialogButton<TextButton>::kViewClassName[] = |
| 109 "TextDialogButton"; |
| 97 } // namespace | 110 } // namespace |
| 98 | 111 |
| 99 /////////////////////////////////////////////////////////////////////////////// | 112 /////////////////////////////////////////////////////////////////////////////// |
| 100 // DialogClientView, public: | 113 // DialogClientView, public: |
| 101 | 114 |
| 102 DialogClientView::DialogClientView(Widget* owner, View* contents_view) | 115 DialogClientView::StyleParams::StyleParams() |
| 116 : button_vedge_margin(kButtonVEdgeMargin), |
| 117 button_hedge_margin(kButtonHEdgeMargin), |
| 118 min_button_width(kDialogMinButtonWidth), |
| 119 button_label_spacing(kDialogButtonLabelSpacing), |
| 120 button_content_spacing(kDialogButtonContentSpacing), |
| 121 text_button_factory(&DialogClientView::CreateNativeStyleDialogButton) { |
| 122 } |
| 123 |
| 124 DialogClientView::DialogClientView(Widget* owner, |
| 125 View* contents_view, |
| 126 const StyleParams ¶ms) |
| 103 : ClientView(owner, contents_view), | 127 : ClientView(owner, contents_view), |
| 128 style_params_(params), |
| 104 ok_button_(NULL), | 129 ok_button_(NULL), |
| 105 cancel_button_(NULL), | 130 cancel_button_(NULL), |
| 106 default_button_(NULL), | 131 default_button_(NULL), |
| 107 extra_view_(NULL), | 132 extra_view_(NULL), |
| 108 size_extra_view_height_to_buttons_(false), | 133 size_extra_view_height_to_buttons_(false), |
| 109 notified_delegate_(false), | 134 notified_delegate_(false), |
| 110 listening_to_focus_(false), | 135 listening_to_focus_(false), |
| 111 saved_focus_manager_(NULL) { | 136 saved_focus_manager_(NULL) { |
| 137 SkColor bg_color = ui::NativeTheme::instance()->GetSystemColor( |
| 138 ui::NativeTheme::kColorId_DialogBackground); |
| 139 set_background(views::Background::CreateSolidBackground(bg_color)); |
| 112 } | 140 } |
| 113 | 141 |
| 114 DialogClientView::~DialogClientView() { | 142 DialogClientView::~DialogClientView() { |
| 115 } | 143 } |
| 116 | 144 |
| 117 void DialogClientView::ShowDialogButtons() { | 145 void DialogClientView::ShowDialogButtons() { |
| 118 DialogDelegate* dd = GetDialogDelegate(); | 146 DialogDelegate* dd = GetDialogDelegate(); |
| 119 int buttons = dd->GetDialogButtons(); | 147 int buttons = dd->GetDialogButtons(); |
| 120 if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { | 148 if (buttons & ui::DIALOG_BUTTON_OK && !ok_button_) { |
| 121 string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); | 149 string16 label = dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_OK); |
| 122 if (label.empty()) | 150 if (label.empty()) |
| 123 label = l10n_util::GetStringUTF16(IDS_APP_OK); | 151 label = l10n_util::GetStringUTF16(IDS_APP_OK); |
| 124 bool is_default_button = | 152 bool is_default_button = |
| 125 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; | 153 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0; |
| 126 ok_button_ = new DialogButton(this, | 154 ok_button_ = style_params_.text_button_factory(this, |
| 127 GetWidget(), | 155 GetWidget(), |
| 128 ui::DIALOG_BUTTON_OK, | 156 ui::DIALOG_BUTTON_OK, |
| 129 label, | 157 label); |
| 130 is_default_button); | |
| 131 ok_button_->SetGroup(kButtonGroup); | 158 ok_button_->SetGroup(kButtonGroup); |
| 132 if (is_default_button) | 159 if (is_default_button) { |
| 133 default_button_ = ok_button_; | 160 default_button_ = ok_button_; |
| 161 default_button_->SetIsDefault(true); |
| 162 } |
| 134 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) | 163 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) |
| 135 ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 164 ok_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 136 AddChildView(ok_button_); | 165 AddChildView(ok_button_); |
| 137 } | 166 } |
| 138 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { | 167 if (buttons & ui::DIALOG_BUTTON_CANCEL && !cancel_button_) { |
| 139 string16 label = | 168 string16 label = |
| 140 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); | 169 dd->GetDialogButtonLabel(ui::DIALOG_BUTTON_CANCEL); |
| 141 if (label.empty()) { | 170 if (label.empty()) { |
| 142 if (buttons & ui::DIALOG_BUTTON_OK) { | 171 if (buttons & ui::DIALOG_BUTTON_OK) { |
| 143 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); | 172 label = l10n_util::GetStringUTF16(IDS_APP_CANCEL); |
| 144 } else { | 173 } else { |
| 145 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); | 174 label = l10n_util::GetStringUTF16(IDS_APP_CLOSE); |
| 146 } | 175 } |
| 147 } | 176 } |
| 148 bool is_default_button = | 177 bool is_default_button = |
| 149 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) | 178 (dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) |
| 150 != 0; | 179 != 0; |
| 151 cancel_button_ = new DialogButton(this, | 180 cancel_button_ = |
| 152 GetWidget(), | 181 style_params_.text_button_factory(this, |
| 153 ui::DIALOG_BUTTON_CANCEL, | 182 GetWidget(), |
| 154 label, | 183 ui::DIALOG_BUTTON_CANCEL, |
| 155 is_default_button); | 184 label); |
| 156 cancel_button_->SetGroup(kButtonGroup); | 185 cancel_button_->SetGroup(kButtonGroup); |
| 157 cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, | 186 cancel_button_->AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, |
| 158 ui::EF_NONE)); | 187 ui::EF_NONE)); |
| 159 if (is_default_button) | 188 if (is_default_button) { |
| 160 default_button_ = ok_button_; | 189 default_button_ = ok_button_; |
| 190 default_button_->SetIsDefault(true); |
| 191 } |
| 161 AddChildView(cancel_button_); | 192 AddChildView(cancel_button_); |
| 162 } | 193 } |
| 163 if (!buttons) { | 194 if (!buttons) { |
| 164 // Register the escape key as an accelerator which will close the window | 195 // Register the escape key as an accelerator which will close the window |
| 165 // if there are no dialog buttons. | 196 // if there are no dialog buttons. |
| 166 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 197 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 167 } | 198 } |
| 168 } | 199 } |
| 169 | 200 |
| 170 void DialogClientView::SetDefaultButton(NativeTextButton* new_default_button) { | 201 void DialogClientView::SetDefaultButton(TextButton* new_default_button) { |
| 171 if (default_button_ && default_button_ != new_default_button) { | 202 if (default_button_ && default_button_ != new_default_button) { |
| 172 default_button_->SetIsDefault(false); | 203 default_button_->SetIsDefault(false); |
| 173 default_button_ = NULL; | 204 default_button_ = NULL; |
| 174 } | 205 } |
| 175 | 206 |
| 176 if (new_default_button) { | 207 if (new_default_button) { |
| 177 default_button_ = new_default_button; | 208 default_button_ = new_default_button; |
| 178 default_button_->SetIsDefault(true); | 209 default_button_->SetIsDefault(true); |
| 179 } | 210 } |
| 180 } | 211 } |
| 181 | 212 |
| 182 void DialogClientView::OnWillChangeFocus(View* focused_before, | 213 void DialogClientView::OnWillChangeFocus(View* focused_before, |
| 183 View* focused_now) { | 214 View* focused_now) { |
| 184 NativeTextButton* new_default_button = NULL; | 215 TextButton* new_default_button = NULL; |
| 185 if (focused_now && | 216 if (focused_now && |
| 186 focused_now->GetClassName() == NativeTextButton::kViewClassName) { | 217 ((focused_now->GetClassName() == |
| 187 new_default_button = static_cast<NativeTextButton*>(focused_now); | 218 DialogButton<NativeTextButton>::kViewClassName) || |
| 219 (focused_now->GetClassName() == |
| 220 DialogButton<TextButton>::kViewClassName))) { |
| 221 new_default_button = static_cast<TextButton*>(focused_now); |
| 188 } else { | 222 } else { |
| 189 // The focused view is not a button, get the default button from the | 223 // The focused view is not a button, get the default button from the |
| 190 // delegate. | 224 // delegate. |
| 191 DialogDelegate* dd = GetDialogDelegate(); | 225 DialogDelegate* dd = GetDialogDelegate(); |
| 192 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) | 226 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_OK) != 0) |
| 193 new_default_button = ok_button_; | 227 new_default_button = ok_button_; |
| 194 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) | 228 if ((dd->GetDefaultDialogButton() & ui::DIALOG_BUTTON_CANCEL) |
| 195 != 0) | 229 != 0) |
| 196 new_default_button = cancel_button_; | 230 new_default_button = cancel_button_; |
| 197 } | 231 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 } | 264 } |
| 231 } | 265 } |
| 232 | 266 |
| 233 void DialogClientView::CancelWindow() { | 267 void DialogClientView::CancelWindow() { |
| 234 // Call the standard Close handler, which checks with the delegate before | 268 // Call the standard Close handler, which checks with the delegate before |
| 235 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, | 269 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, |
| 236 // so that the close box on the window also shares this code path. | 270 // so that the close box on the window also shares this code path. |
| 237 Close(); | 271 Close(); |
| 238 } | 272 } |
| 239 | 273 |
| 274 // static |
| 275 TextButton* DialogClientView::CreateNativeStyleDialogButton( |
| 276 ButtonListener* listener, |
| 277 Widget* owner, |
| 278 ui::DialogButton type, |
| 279 const string16& title) |
| 280 { |
| 281 return new DialogButton<NativeTextButton>(listener, owner, type, title); |
| 282 } |
| 283 |
| 284 // static |
| 285 TextButton* DialogClientView::CreateChromeStyleDialogButton( |
| 286 ButtonListener* listener, |
| 287 Widget* owner, |
| 288 ui::DialogButton type, |
| 289 const string16& title) |
| 290 { |
| 291 DialogButton<TextButton>* button = |
| 292 new DialogButton<TextButton>(listener, owner, type, title); |
| 293 ApplyChromeStyle(button); |
| 294 return button; |
| 295 } |
| 296 |
| 240 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
| 241 // DialogClientView, View overrides: | 298 // DialogClientView, View overrides: |
| 242 | 299 |
| 243 void DialogClientView::NativeViewHierarchyChanged( | 300 void DialogClientView::NativeViewHierarchyChanged( |
| 244 bool attached, | 301 bool attached, |
| 245 gfx::NativeView native_view, | 302 gfx::NativeView native_view, |
| 246 internal::RootView* root_view) { | 303 internal::RootView* root_view) { |
| 247 if (attached) { | 304 if (attached) { |
| 248 UpdateFocusListener(); | 305 UpdateFocusListener(); |
| 249 } | 306 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return this; | 342 return this; |
| 286 } | 343 } |
| 287 | 344 |
| 288 const DialogClientView* DialogClientView::AsDialogClientView() const { | 345 const DialogClientView* DialogClientView::AsDialogClientView() const { |
| 289 return this; | 346 return this; |
| 290 } | 347 } |
| 291 | 348 |
| 292 //////////////////////////////////////////////////////////////////////////////// | 349 //////////////////////////////////////////////////////////////////////////////// |
| 293 // DialogClientView, View overrides: | 350 // DialogClientView, View overrides: |
| 294 | 351 |
| 295 void DialogClientView::OnPaint(gfx::Canvas* canvas) { | |
| 296 SkColor bg_color = ui::NativeTheme::instance()->GetSystemColor( | |
| 297 ui::NativeTheme::kColorId_DialogBackground); | |
| 298 canvas->FillRect(GetLocalBounds(), bg_color); | |
| 299 } | |
| 300 | |
| 301 void DialogClientView::PaintChildren(gfx::Canvas* canvas) { | 352 void DialogClientView::PaintChildren(gfx::Canvas* canvas) { |
| 302 View::PaintChildren(canvas); | 353 View::PaintChildren(canvas); |
| 303 if (!GetWidget()->IsMaximized() && !GetWidget()->IsMinimized()) | 354 if (!GetWidget()->IsMaximized() && !GetWidget()->IsMinimized()) |
| 304 PaintSizeBox(canvas); | 355 PaintSizeBox(canvas); |
| 305 } | 356 } |
| 306 | 357 |
| 307 void DialogClientView::Layout() { | 358 void DialogClientView::Layout() { |
| 308 if (has_dialog_buttons()) | 359 if (has_dialog_buttons()) |
| 309 LayoutDialogButtons(); | 360 LayoutDialogButtons(); |
| 310 LayoutContentsView(); | 361 LayoutContentsView(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 width += GetButtonWidth(ui::DIALOG_BUTTON_OK); | 393 width += GetButtonWidth(ui::DIALOG_BUTTON_OK); |
| 343 if (cancel_button_) | 394 if (cancel_button_) |
| 344 width += kRelatedButtonHSpacing; | 395 width += kRelatedButtonHSpacing; |
| 345 } | 396 } |
| 346 if (extra_view_) { | 397 if (extra_view_) { |
| 347 width += extra_view_->GetPreferredSize().width(); | 398 width += extra_view_->GetPreferredSize().width(); |
| 348 if (cancel_button_ || ok_button_) | 399 if (cancel_button_ || ok_button_) |
| 349 width += kRelatedButtonHSpacing; | 400 width += kRelatedButtonHSpacing; |
| 350 } | 401 } |
| 351 if (width > 0) { | 402 if (width > 0) { |
| 352 width += 2 * kButtonHEdgeMargin; | 403 width += 2 * style_params_.button_hedge_margin; |
| 353 prefsize.set_width(std::max(prefsize.width(), width)); | 404 prefsize.set_width(std::max(prefsize.width(), width)); |
| 354 } | 405 } |
| 355 } | 406 } |
| 356 prefsize.Enlarge(0, button_height); | 407 prefsize.Enlarge(0, button_height); |
| 357 return prefsize; | 408 return prefsize; |
| 358 } | 409 } |
| 359 | 410 |
| 360 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 411 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 361 // We only expect Escape key. | 412 // We only expect Escape key. |
| 362 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); | 413 DCHECK(accelerator.key_code() == ui::VKEY_ESCAPE); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // TODO(port): paint size box | 462 // TODO(port): paint size box |
| 412 #endif | 463 #endif |
| 413 } | 464 } |
| 414 } | 465 } |
| 415 | 466 |
| 416 int DialogClientView::GetButtonWidth(int button) const { | 467 int DialogClientView::GetButtonWidth(int button) const { |
| 417 DialogDelegate* dd = GetDialogDelegate(); | 468 DialogDelegate* dd = GetDialogDelegate(); |
| 418 string16 button_label = dd->GetDialogButtonLabel( | 469 string16 button_label = dd->GetDialogButtonLabel( |
| 419 static_cast<ui::DialogButton>(button)); | 470 static_cast<ui::DialogButton>(button)); |
| 420 int string_width = GetDialogButtonFont().GetStringWidth(button_label); | 471 int string_width = GetDialogButtonFont().GetStringWidth(button_label); |
| 421 return std::max(string_width + kDialogButtonLabelSpacing, | 472 return std::max(string_width + style_params_.button_label_spacing, |
| 422 kDialogMinButtonWidth); | 473 style_params_.min_button_width); |
| 423 } | 474 } |
| 424 | 475 |
| 425 int DialogClientView::GetButtonsHeight() const { | 476 int DialogClientView::GetButtonsHeight() const { |
| 426 int button_height = 0; | 477 int button_height = 0; |
| 427 if (cancel_button_) | 478 if (cancel_button_) |
| 428 button_height = std::max(button_height, | 479 button_height = std::max(button_height, |
| 429 cancel_button_->GetPreferredSize().height()); | 480 cancel_button_->GetPreferredSize().height()); |
| 430 if (ok_button_) | 481 if (ok_button_) |
| 431 button_height = std::max(button_height, | 482 button_height = std::max(button_height, |
| 432 ok_button_->GetPreferredSize().height()); | 483 ok_button_->GetPreferredSize().height()); |
| 433 return button_height; | 484 return button_height; |
| 434 } | 485 } |
| 435 | 486 |
| 436 int DialogClientView::GetDialogButtonsAreaHeight() const { | 487 int DialogClientView::GetDialogButtonsAreaHeight() const { |
| 437 return !has_dialog_buttons() ? 0 : | 488 return !has_dialog_buttons() ? 0 : |
| 438 GetButtonsHeight() + kDialogButtonContentSpacing + kButtonVEdgeMargin; | 489 GetButtonsHeight() + style_params_.button_content_spacing + |
| 490 style_params_.button_vedge_margin; |
| 439 } | 491 } |
| 440 | 492 |
| 441 void DialogClientView::LayoutDialogButtons() { | 493 void DialogClientView::LayoutDialogButtons() { |
| 442 gfx::Rect lb = GetContentsBounds(); | 494 gfx::Rect lb = GetContentsBounds(); |
| 443 gfx::Rect extra_bounds; | 495 gfx::Rect extra_bounds; |
| 444 int bottom_y = lb.bottom() - kButtonVEdgeMargin; | 496 int bottom_y = lb.bottom() - style_params_.button_vedge_margin; |
| 445 int button_height = GetButtonsHeight(); | 497 int button_height = GetButtonsHeight(); |
| 446 if (cancel_button_) { | 498 if (cancel_button_) { |
| 447 gfx::Size ps = cancel_button_->GetPreferredSize(); | 499 gfx::Size ps = cancel_button_->GetPreferredSize(); |
| 448 int button_width = std::max( | 500 int button_width = std::max( |
| 449 GetButtonWidth(ui::DIALOG_BUTTON_CANCEL), ps.width()); | 501 GetButtonWidth(ui::DIALOG_BUTTON_CANCEL), ps.width()); |
| 450 int button_x = lb.right() - button_width - kButtonHEdgeMargin; | 502 int button_x = lb.right() - button_width - |
| 503 style_params_.button_hedge_margin; |
| 451 int button_y = bottom_y - ps.height(); | 504 int button_y = bottom_y - ps.height(); |
| 452 cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); | 505 cancel_button_->SetBounds(button_x, button_y, button_width, ps.height()); |
| 453 // The extra view bounds are dependent on this button. | 506 // The extra view bounds are dependent on this button. |
| 454 extra_bounds.set_width(std::max(0, cancel_button_->x())); | 507 extra_bounds.set_width(std::max(0, cancel_button_->x())); |
| 455 extra_bounds.set_y(cancel_button_->y()); | 508 extra_bounds.set_y(cancel_button_->y()); |
| 456 } | 509 } |
| 457 if (ok_button_) { | 510 if (ok_button_) { |
| 458 gfx::Size ps = ok_button_->GetPreferredSize(); | 511 gfx::Size ps = ok_button_->GetPreferredSize(); |
| 459 int button_width = std::max( | 512 int button_width = std::max( |
| 460 GetButtonWidth(ui::DIALOG_BUTTON_OK), ps.width()); | 513 GetButtonWidth(ui::DIALOG_BUTTON_OK), ps.width()); |
| 461 int ok_button_right = lb.right() - kButtonHEdgeMargin; | 514 int ok_button_right = lb.right() - style_params_.button_hedge_margin; |
| 462 if (cancel_button_) | 515 if (cancel_button_) |
| 463 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; | 516 ok_button_right = cancel_button_->x() - kRelatedButtonHSpacing; |
| 464 int button_x = ok_button_right - button_width; | 517 int button_x = ok_button_right - button_width; |
| 465 int button_y = bottom_y - ps.height(); | 518 int button_y = bottom_y - ps.height(); |
| 466 ok_button_->SetBounds(button_x, button_y, ok_button_right - button_x, | 519 ok_button_->SetBounds(button_x, button_y, ok_button_right - button_x, |
| 467 ps.height()); | 520 ps.height()); |
| 468 // The extra view bounds are dependent on this button. | 521 // The extra view bounds are dependent on this button. |
| 469 extra_bounds.set_width(std::max(0, ok_button_->x())); | 522 extra_bounds.set_width(std::max(0, ok_button_->x())); |
| 470 extra_bounds.set_y(ok_button_->y()); | 523 extra_bounds.set_y(ok_button_->y()); |
| 471 } | 524 } |
| 472 if (extra_view_) { | 525 if (extra_view_) { |
| 473 gfx::Size ps = extra_view_->GetPreferredSize(); | 526 gfx::Size ps = extra_view_->GetPreferredSize(); |
| 474 extra_bounds.set_x(lb.x() + kButtonHEdgeMargin); | 527 extra_bounds.set_x(lb.x() + style_params_.button_hedge_margin); |
| 475 int height = size_extra_view_height_to_buttons_ ? | 528 int height = size_extra_view_height_to_buttons_ ? |
| 476 std::max(ps.height(), button_height) : ps.height(); | 529 std::max(ps.height(), button_height) : ps.height(); |
| 477 extra_bounds.set_height(height); | 530 extra_bounds.set_height(height); |
| 478 extra_view_->SetBoundsRect(extra_bounds); | 531 extra_view_->SetBoundsRect(extra_bounds); |
| 479 } | 532 } |
| 480 } | 533 } |
| 481 | 534 |
| 482 void DialogClientView::LayoutContentsView() { | 535 void DialogClientView::LayoutContentsView() { |
| 483 gfx::Rect lb = GetContentsBounds(); | 536 gfx::Rect lb = GetContentsBounds(); |
| 484 lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight())); | 537 lb.set_height(std::max(0, lb.height() - GetDialogButtonsAreaHeight())); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 } | 575 } |
| 523 saved_focus_manager_ = focus_manager; | 576 saved_focus_manager_ = focus_manager; |
| 524 // Listen for focus change events so we can update the default button. | 577 // Listen for focus change events so we can update the default button. |
| 525 if (focus_manager) { | 578 if (focus_manager) { |
| 526 focus_manager->AddFocusChangeListener(this); | 579 focus_manager->AddFocusChangeListener(this); |
| 527 listening_to_focus_ = true; | 580 listening_to_focus_ = true; |
| 528 } | 581 } |
| 529 } | 582 } |
| 530 | 583 |
| 531 } // namespace views | 584 } // namespace views |
| OLD | NEW |