| 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 "chrome/browser/ui/views/keyboard_overlay_dialog_view.h" | 5 #include "chrome/browser/ui/views/keyboard_overlay_dialog_view.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 10 #include "chrome/browser/ui/browser_dialogs.h" | 10 #include "chrome/browser/ui/browser_dialogs.h" |
| 11 #include "chrome/browser/ui/views/keyboard_overlay_delegate.h" | 11 #include "chrome/browser/ui/views/keyboard_overlay_delegate.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/gfx/screen.h" | 14 #include "ui/gfx/screen.h" |
| 15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 16 #include "ui/web_dialogs/web_dialog_delegate.h" | 16 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 17 | 17 |
| 18 using ui::WebDialogDelegate; | 18 using ui::WebDialogDelegate; |
| 19 | 19 |
| 20 namespace { |
| 21 // Store the pointer to the view currently shown. |
| 22 KeyboardOverlayDialogView* g_instance = NULL; |
| 23 } |
| 24 |
| 20 KeyboardOverlayDialogView::KeyboardOverlayDialogView( | 25 KeyboardOverlayDialogView::KeyboardOverlayDialogView( |
| 21 Profile* profile, | 26 Profile* profile, |
| 22 WebDialogDelegate* delegate) | 27 WebDialogDelegate* delegate) |
| 23 : WebDialogView(profile, NULL, delegate) { | 28 : WebDialogView(profile, NULL, delegate) { |
| 24 } | 29 } |
| 25 | 30 |
| 26 KeyboardOverlayDialogView::~KeyboardOverlayDialogView() { | 31 KeyboardOverlayDialogView::~KeyboardOverlayDialogView() { |
| 27 } | 32 } |
| 28 | 33 |
| 29 void KeyboardOverlayDialogView::ShowDialog() { | 34 void KeyboardOverlayDialogView::ShowDialog() { |
| 35 // Ignore the call if another view is already shown. |
| 36 if (g_instance) |
| 37 return; |
| 30 | 38 |
| 31 KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( | 39 KeyboardOverlayDelegate* delegate = new KeyboardOverlayDelegate( |
| 32 l10n_util::GetStringUTF16(IDS_KEYBOARD_OVERLAY_TITLE)); | 40 l10n_util::GetStringUTF16(IDS_KEYBOARD_OVERLAY_TITLE)); |
| 33 KeyboardOverlayDialogView* view = new KeyboardOverlayDialogView( | 41 KeyboardOverlayDialogView* view = new KeyboardOverlayDialogView( |
| 34 ProfileManager::GetDefaultProfileOrOffTheRecord(), delegate); | 42 ProfileManager::GetDefaultProfileOrOffTheRecord(), delegate); |
| 35 delegate->set_view(view); | 43 delegate->set_view(view); |
| 36 | 44 |
| 37 views::Widget* widget = new views::Widget; | 45 views::Widget* widget = new views::Widget; |
| 38 views::Widget::InitParams params( | 46 views::Widget::InitParams params( |
| 39 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 47 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 40 params.delegate = view; | 48 params.delegate = view; |
| 41 widget->Init(params); | 49 widget->Init(params); |
| 42 | 50 |
| 43 // Show the widget at the bottom of the work area. | 51 // Show the widget at the bottom of the work area. |
| 44 gfx::Size size; | 52 gfx::Size size; |
| 45 delegate->GetDialogSize(&size); | 53 delegate->GetDialogSize(&size); |
| 46 gfx::Rect rect = gfx::Screen::GetMonitorNearestWindow( | 54 gfx::Rect rect = gfx::Screen::GetMonitorNearestWindow( |
| 47 view->GetWidget()->GetNativeView()).work_area(); | 55 view->GetWidget()->GetNativeView()).work_area(); |
| 48 gfx::Rect bounds((rect.width() - size.width()) / 2, | 56 gfx::Rect bounds((rect.width() - size.width()) / 2, |
| 49 rect.height() - size.height(), | 57 rect.height() - size.height(), |
| 50 size.width(), | 58 size.width(), |
| 51 size.height()); | 59 size.height()); |
| 52 view->GetWidget()->SetBounds(bounds); | 60 view->GetWidget()->SetBounds(bounds); |
| 53 view->GetWidget()->Show(); | 61 view->GetWidget()->Show(); |
| 62 |
| 63 g_instance = view; |
| 54 } | 64 } |
| 65 |
| 66 void KeyboardOverlayDialogView::WindowClosing() { |
| 67 g_instance = NULL; |
| 68 } |
| OLD | NEW |