| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/window/dialog_client_view.h" | 5 #include "views/window/dialog_client_view.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <uxtheme.h> | 9 #include <uxtheme.h> |
| 10 #include <vsstyle.h> | 10 #include <vsstyle.h> |
| 11 #else | 11 #else |
| 12 #include <gtk/gtk.h> | 12 #include <gtk/gtk.h> |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 | 16 |
| 17 #include "app/keyboard_codes.h" |
| 17 #include "app/l10n_util.h" | 18 #include "app/l10n_util.h" |
| 18 #include "app/resource_bundle.h" | 19 #include "app/resource_bundle.h" |
| 19 #include "base/keyboard_codes.h" | |
| 20 #include "gfx/canvas_skia.h" | 20 #include "gfx/canvas_skia.h" |
| 21 #include "gfx/font.h" | 21 #include "gfx/font.h" |
| 22 #include "grit/app_strings.h" | 22 #include "grit/app_strings.h" |
| 23 #include "views/controls/button/native_button.h" | 23 #include "views/controls/button/native_button.h" |
| 24 #include "views/standard_layout.h" | 24 #include "views/standard_layout.h" |
| 25 #include "views/window/dialog_delegate.h" | 25 #include "views/window/dialog_delegate.h" |
| 26 #include "views/window/window.h" | 26 #include "views/window/window.h" |
| 27 | 27 |
| 28 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 29 #include "gfx/native_theme_win.h" | 29 #include "gfx/native_theme_win.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 label = l10n_util::GetString(IDS_APP_OK); | 132 label = l10n_util::GetString(IDS_APP_OK); |
| 133 bool is_default_button = | 133 bool is_default_button = |
| 134 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0; | 134 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_OK) != 0; |
| 135 ok_button_ = new DialogButton(this, window(), | 135 ok_button_ = new DialogButton(this, window(), |
| 136 MessageBoxFlags::DIALOGBUTTON_OK, label, | 136 MessageBoxFlags::DIALOGBUTTON_OK, label, |
| 137 is_default_button); | 137 is_default_button); |
| 138 ok_button_->SetGroup(kButtonGroup); | 138 ok_button_->SetGroup(kButtonGroup); |
| 139 if (is_default_button) | 139 if (is_default_button) |
| 140 default_button_ = ok_button_; | 140 default_button_ = ok_button_; |
| 141 if (!(buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL)) | 141 if (!(buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL)) |
| 142 ok_button_->AddAccelerator(Accelerator(base::VKEY_ESCAPE, | 142 ok_button_->AddAccelerator(Accelerator(app::VKEY_ESCAPE, |
| 143 false, false, false)); | 143 false, false, false)); |
| 144 AddChildView(ok_button_); | 144 AddChildView(ok_button_); |
| 145 } | 145 } |
| 146 if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) { | 146 if (buttons & MessageBoxFlags::DIALOGBUTTON_CANCEL && !cancel_button_) { |
| 147 std::wstring label = | 147 std::wstring label = |
| 148 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL); | 148 dd->GetDialogButtonLabel(MessageBoxFlags::DIALOGBUTTON_CANCEL); |
| 149 if (label.empty()) { | 149 if (label.empty()) { |
| 150 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) { | 150 if (buttons & MessageBoxFlags::DIALOGBUTTON_OK) { |
| 151 label = l10n_util::GetString(IDS_APP_CANCEL); | 151 label = l10n_util::GetString(IDS_APP_CANCEL); |
| 152 } else { | 152 } else { |
| 153 label = l10n_util::GetString(IDS_APP_CLOSE); | 153 label = l10n_util::GetString(IDS_APP_CLOSE); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 bool is_default_button = | 156 bool is_default_button = |
| 157 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL) | 157 (dd->GetDefaultDialogButton() & MessageBoxFlags::DIALOGBUTTON_CANCEL) |
| 158 != 0; | 158 != 0; |
| 159 cancel_button_ = new DialogButton(this, window(), | 159 cancel_button_ = new DialogButton(this, window(), |
| 160 MessageBoxFlags::DIALOGBUTTON_CANCEL, | 160 MessageBoxFlags::DIALOGBUTTON_CANCEL, |
| 161 label, is_default_button); | 161 label, is_default_button); |
| 162 cancel_button_->SetGroup(kButtonGroup); | 162 cancel_button_->SetGroup(kButtonGroup); |
| 163 cancel_button_->AddAccelerator(Accelerator(base::VKEY_ESCAPE, | 163 cancel_button_->AddAccelerator(Accelerator(app::VKEY_ESCAPE, |
| 164 false, false, false)); | 164 false, false, false)); |
| 165 if (is_default_button) | 165 if (is_default_button) |
| 166 default_button_ = ok_button_; | 166 default_button_ = ok_button_; |
| 167 AddChildView(cancel_button_); | 167 AddChildView(cancel_button_); |
| 168 } | 168 } |
| 169 if (!buttons) { | 169 if (!buttons) { |
| 170 // Register the escape key as an accelerator which will close the window | 170 // Register the escape key as an accelerator which will close the window |
| 171 // if there are no dialog buttons. | 171 // if there are no dialog buttons. |
| 172 AddAccelerator(Accelerator(base::VKEY_ESCAPE, false, false, false)); | 172 AddAccelerator(Accelerator(app::VKEY_ESCAPE, false, false, false)); |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 | 175 |
| 176 void DialogClientView::SetDefaultButton(NativeButton* new_default_button) { | 176 void DialogClientView::SetDefaultButton(NativeButton* new_default_button) { |
| 177 if (default_button_ && default_button_ != new_default_button) { | 177 if (default_button_ && default_button_ != new_default_button) { |
| 178 default_button_->SetIsDefault(false); | 178 default_button_->SetIsDefault(false); |
| 179 default_button_ = NULL; | 179 default_button_ = NULL; |
| 180 } | 180 } |
| 181 | 181 |
| 182 if (new_default_button) { | 182 if (new_default_button) { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 if (bottom_view_) { | 380 if (bottom_view_) { |
| 381 gfx::Size bottom_pref = bottom_view_->GetPreferredSize(); | 381 gfx::Size bottom_pref = bottom_view_->GetPreferredSize(); |
| 382 prefsize.Enlarge(0, bottom_pref.height() + kButtonVEdgeMargin); | 382 prefsize.Enlarge(0, bottom_pref.height() + kButtonVEdgeMargin); |
| 383 } | 383 } |
| 384 prefsize.Enlarge(0, button_height); | 384 prefsize.Enlarge(0, button_height); |
| 385 return prefsize; | 385 return prefsize; |
| 386 } | 386 } |
| 387 | 387 |
| 388 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { | 388 bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) { |
| 389 // We only expect Escape key. | 389 // We only expect Escape key. |
| 390 DCHECK(accelerator.GetKeyCode() == base::VKEY_ESCAPE); | 390 DCHECK(accelerator.GetKeyCode() == app::VKEY_ESCAPE); |
| 391 Close(); | 391 Close(); |
| 392 return true; | 392 return true; |
| 393 } | 393 } |
| 394 | 394 |
| 395 //////////////////////////////////////////////////////////////////////////////// | 395 //////////////////////////////////////////////////////////////////////////////// |
| 396 // DialogClientView, ButtonListener implementation: | 396 // DialogClientView, ButtonListener implementation: |
| 397 | 397 |
| 398 void DialogClientView::ButtonPressed( | 398 void DialogClientView::ButtonPressed( |
| 399 Button* sender, const views::Event& event) { | 399 Button* sender, const views::Event& event) { |
| 400 // We NULL check the delegate here since the buttons can receive WM_COMMAND | 400 // We NULL check the delegate here since the buttons can receive WM_COMMAND |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 void DialogClientView::InitClass() { | 562 void DialogClientView::InitClass() { |
| 563 static bool initialized = false; | 563 static bool initialized = false; |
| 564 if (!initialized) { | 564 if (!initialized) { |
| 565 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 565 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 566 dialog_button_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); | 566 dialog_button_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); |
| 567 initialized = true; | 567 initialized = true; |
| 568 } | 568 } |
| 569 } | 569 } |
| 570 | 570 |
| 571 } // namespace views | 571 } // namespace views |
| OLD | NEW |