| 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/content/keyboard_overlay/keyboard_overlay_delegate.h" | 5 #include "ash/content/keyboard_overlay/keyboard_overlay_delegate.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "content/public/browser/web_ui.h" | 14 #include "content/public/browser/web_ui.h" |
| 15 #include "content/public/browser/web_ui_message_handler.h" | 15 #include "content/public/browser/web_ui_message_handler.h" |
| 16 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
| 17 #include "ui/gfx/screen.h" | 17 #include "ui/display/screen.h" |
| 18 #include "ui/views/controls/webview/web_dialog_view.h" | 18 #include "ui/views/controls/webview/web_dialog_view.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 using content::WebContents; | 21 using content::WebContents; |
| 22 using content::WebUIMessageHandler; | 22 using content::WebUIMessageHandler; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const int kBaseWidth = 1252; | 26 const int kBaseWidth = 1252; |
| 27 const int kBaseHeight = 516; | 27 const int kBaseHeight = 516; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 views::Widget::InitParams params( | 70 views::Widget::InitParams params( |
| 71 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 71 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 72 params.context = Shell::GetPrimaryRootWindow(); | 72 params.context = Shell::GetPrimaryRootWindow(); |
| 73 params.delegate = view; | 73 params.delegate = view; |
| 74 widget_->Init(params); | 74 widget_->Init(params); |
| 75 | 75 |
| 76 // Show the widget at the bottom of the work area. | 76 // Show the widget at the bottom of the work area. |
| 77 gfx::Size size; | 77 gfx::Size size; |
| 78 GetDialogSize(&size); | 78 GetDialogSize(&size); |
| 79 const gfx::Rect& rect = | 79 const gfx::Rect& rect = |
| 80 gfx::Screen::GetScreen() | 80 display::Screen::GetScreen() |
| 81 ->GetDisplayNearestWindow(widget_->GetNativeView()) | 81 ->GetDisplayNearestWindow(widget_->GetNativeView()) |
| 82 .work_area(); | 82 .work_area(); |
| 83 gfx::Rect bounds(rect.x() + (rect.width() - size.width()) / 2, | 83 gfx::Rect bounds(rect.x() + (rect.width() - size.width()) / 2, |
| 84 rect.bottom() - size.height(), size.width(), size.height()); | 84 rect.bottom() - size.height(), size.width(), size.height()); |
| 85 widget_->SetBounds(bounds); | 85 widget_->SetBounds(bounds); |
| 86 | 86 |
| 87 // The widget will be shown when the web contents gets ready to display. | 87 // The widget will be shown when the web contents gets ready to display. |
| 88 return widget_; | 88 return widget_; |
| 89 } | 89 } |
| 90 | 90 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 101 } | 101 } |
| 102 | 102 |
| 103 void KeyboardOverlayDelegate::GetWebUIMessageHandlers( | 103 void KeyboardOverlayDelegate::GetWebUIMessageHandlers( |
| 104 std::vector<WebUIMessageHandler*>* handlers) const { | 104 std::vector<WebUIMessageHandler*>* handlers) const { |
| 105 handlers->push_back(new PaintMessageHandler(widget_)); | 105 handlers->push_back(new PaintMessageHandler(widget_)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 void KeyboardOverlayDelegate::GetDialogSize(gfx::Size* size) const { | 108 void KeyboardOverlayDelegate::GetDialogSize(gfx::Size* size) const { |
| 109 using std::min; | 109 using std::min; |
| 110 DCHECK(widget_); | 110 DCHECK(widget_); |
| 111 gfx::Rect rect = gfx::Screen::GetScreen() | 111 gfx::Rect rect = display::Screen::GetScreen() |
| 112 ->GetDisplayNearestWindow(widget_->GetNativeView()) | 112 ->GetDisplayNearestWindow(widget_->GetNativeView()) |
| 113 .work_area(); | 113 .work_area(); |
| 114 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); | 114 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); |
| 115 const int height = width * kBaseHeight / kBaseWidth; | 115 const int height = width * kBaseHeight / kBaseWidth; |
| 116 size->SetSize(width, height); | 116 size->SetSize(width, height); |
| 117 } | 117 } |
| 118 | 118 |
| 119 std::string KeyboardOverlayDelegate::GetDialogArgs() const { | 119 std::string KeyboardOverlayDelegate::GetDialogArgs() const { |
| 120 return "[]"; | 120 return "[]"; |
| 121 } | 121 } |
| 122 | 122 |
| 123 void KeyboardOverlayDelegate::OnDialogClosed(const std::string& json_retval) { | 123 void KeyboardOverlayDelegate::OnDialogClosed(const std::string& json_retval) { |
| 124 delete this; | 124 delete this; |
| 125 return; | 125 return; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, | 128 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, |
| 129 bool* out_close_dialog) {} | 129 bool* out_close_dialog) {} |
| 130 | 130 |
| 131 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { | 131 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { |
| 132 return false; | 132 return false; |
| 133 } | 133 } |
| 134 | 134 |
| 135 bool KeyboardOverlayDelegate::HandleContextMenu( | 135 bool KeyboardOverlayDelegate::HandleContextMenu( |
| 136 const content::ContextMenuParams& params) { | 136 const content::ContextMenuParams& params) { |
| 137 return true; | 137 return true; |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace ash | 140 } // namespace ash |
| OLD | NEW |