| 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 "ash/keyboard_overlay/keyboard_overlay_delegate.h" | 5 #include "ash/keyboard_overlay/keyboard_overlay_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/shell.h" |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
| 14 #include "content/public/browser/web_ui_message_handler.h" | 15 #include "content/public/browser/web_ui_message_handler.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 17 #include "ui/views/controls/webview/web_dialog_view.h" | 18 #include "ui/views/controls/webview/web_dialog_view.h" |
| 18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 base::Bind(&PaintMessageHandler::DidPaint, base::Unretained(this))); | 52 base::Bind(&PaintMessageHandler::DidPaint, base::Unretained(this))); |
| 52 } | 53 } |
| 53 | 54 |
| 54 void PaintMessageHandler::DidPaint(const ListValue* args) { | 55 void PaintMessageHandler::DidPaint(const ListValue* args) { |
| 55 // Show the widget after the web content has been painted. | 56 // Show the widget after the web content has been painted. |
| 56 widget_->Show(); | 57 widget_->Show(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 } // namespace | 60 } // namespace |
| 60 | 61 |
| 62 namespace ash { |
| 63 |
| 61 KeyboardOverlayDelegate::KeyboardOverlayDelegate(const string16& title, | 64 KeyboardOverlayDelegate::KeyboardOverlayDelegate(const string16& title, |
| 62 const GURL& url) | 65 const GURL& url) |
| 63 : title_(title), | 66 : title_(title), |
| 64 url_(url), | 67 url_(url), |
| 65 view_(NULL) { | 68 view_(NULL) { |
| 66 } | 69 } |
| 67 | 70 |
| 68 KeyboardOverlayDelegate::~KeyboardOverlayDelegate() { | 71 KeyboardOverlayDelegate::~KeyboardOverlayDelegate() { |
| 69 } | 72 } |
| 70 | 73 |
| 71 void KeyboardOverlayDelegate::Show(views::WebDialogView* view) { | 74 void KeyboardOverlayDelegate::Show(views::WebDialogView* view) { |
| 72 view_ = view; | 75 view_ = view; |
| 73 | 76 |
| 74 views::Widget* widget = new views::Widget; | 77 views::Widget* widget = new views::Widget; |
| 75 views::Widget::InitParams params( | 78 views::Widget::InitParams params( |
| 76 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 79 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 77 params.delegate = view; | 80 params.delegate = view; |
| 78 widget->Init(params); | 81 widget->Init(params); |
| 79 | 82 |
| 80 // Show the widget at the bottom of the work area. | 83 // Show the widget at the bottom of the work area. |
| 81 gfx::Size size; | 84 gfx::Size size; |
| 82 GetDialogSize(&size); | 85 GetDialogSize(&size); |
| 83 const gfx::Rect& rect = gfx::Screen::GetDisplayNearestWindow( | 86 const gfx::Rect& rect = Shell::GetAshScreen()->GetDisplayNearestWindow( |
| 84 widget->GetNativeView()).work_area(); | 87 widget->GetNativeView()).work_area(); |
| 85 gfx::Rect bounds((rect.width() - size.width()) / 2, | 88 gfx::Rect bounds((rect.width() - size.width()) / 2, |
| 86 rect.height() - size.height(), | 89 rect.height() - size.height(), |
| 87 size.width(), | 90 size.width(), |
| 88 size.height()); | 91 size.height()); |
| 89 widget->SetBounds(bounds); | 92 widget->SetBounds(bounds); |
| 90 | 93 |
| 91 // The widget will be shown when the web contents gets ready to display. | 94 // The widget will be shown when the web contents gets ready to display. |
| 92 } | 95 } |
| 93 | 96 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 105 | 108 |
| 106 void KeyboardOverlayDelegate::GetWebUIMessageHandlers( | 109 void KeyboardOverlayDelegate::GetWebUIMessageHandlers( |
| 107 std::vector<WebUIMessageHandler*>* handlers) const { | 110 std::vector<WebUIMessageHandler*>* handlers) const { |
| 108 handlers->push_back(new PaintMessageHandler(view_->GetWidget())); | 111 handlers->push_back(new PaintMessageHandler(view_->GetWidget())); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void KeyboardOverlayDelegate::GetDialogSize( | 114 void KeyboardOverlayDelegate::GetDialogSize( |
| 112 gfx::Size* size) const { | 115 gfx::Size* size) const { |
| 113 using std::min; | 116 using std::min; |
| 114 DCHECK(view_); | 117 DCHECK(view_); |
| 115 gfx::Rect rect = gfx::Screen::GetDisplayNearestWindow( | 118 gfx::Rect rect = ash::Shell::GetAshScreen()->GetDisplayNearestWindow( |
| 116 view_->GetWidget()->GetNativeView()).bounds(); | 119 view_->GetWidget()->GetNativeView()).bounds(); |
| 117 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); | 120 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); |
| 118 const int height = width * kBaseHeight / kBaseWidth; | 121 const int height = width * kBaseHeight / kBaseWidth; |
| 119 size->SetSize(width, height); | 122 size->SetSize(width, height); |
| 120 } | 123 } |
| 121 | 124 |
| 122 std::string KeyboardOverlayDelegate::GetDialogArgs() const { | 125 std::string KeyboardOverlayDelegate::GetDialogArgs() const { |
| 123 return "[]"; | 126 return "[]"; |
| 124 } | 127 } |
| 125 | 128 |
| 126 void KeyboardOverlayDelegate::OnDialogClosed( | 129 void KeyboardOverlayDelegate::OnDialogClosed( |
| 127 const std::string& json_retval) { | 130 const std::string& json_retval) { |
| 128 delete this; | 131 delete this; |
| 129 return; | 132 return; |
| 130 } | 133 } |
| 131 | 134 |
| 132 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, | 135 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, |
| 133 bool* out_close_dialog) { | 136 bool* out_close_dialog) { |
| 134 } | 137 } |
| 135 | 138 |
| 136 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { | 139 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { |
| 137 return false; | 140 return false; |
| 138 } | 141 } |
| 139 | 142 |
| 140 bool KeyboardOverlayDelegate::HandleContextMenu( | 143 bool KeyboardOverlayDelegate::HandleContextMenu( |
| 141 const content::ContextMenuParams& params) { | 144 const content::ContextMenuParams& params) { |
| 142 return true; | 145 return true; |
| 143 } | 146 } |
| 147 |
| 148 } // namespace ash |
| OLD | NEW |