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