| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 widget_ = new views::Widget; | 71 widget_ = new views::Widget; |
| 72 views::Widget::InitParams params( | 72 views::Widget::InitParams params( |
| 73 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 73 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 74 params.context = Shell::GetPrimaryRootWindow(); | 74 params.context = Shell::GetPrimaryRootWindow(); |
| 75 params.delegate = view; | 75 params.delegate = view; |
| 76 widget_->Init(params); | 76 widget_->Init(params); |
| 77 | 77 |
| 78 // Show the widget at the bottom of the work area. | 78 // Show the widget at the bottom of the work area. |
| 79 gfx::Size size; | 79 gfx::Size size; |
| 80 GetDialogSize(&size); | 80 GetDialogSize(&size); |
| 81 const gfx::Rect rect = display::Screen::GetScreen() | 81 const gfx::Rect rect = |
| 82 ->GetDisplayNearestWindow(widget_->GetNativeView()) | 82 display::Screen::GetScreen() |
| 83 .work_area(); | 83 ->GetDisplayNearestWindow(widget_->GetNativeWindow()) |
| 84 .work_area(); |
| 84 gfx::Rect bounds(rect.x() + (rect.width() - size.width()) / 2, | 85 gfx::Rect bounds(rect.x() + (rect.width() - size.width()) / 2, |
| 85 rect.y() + (rect.height() - size.height()) / 2, size.width(), | 86 rect.y() + (rect.height() - size.height()) / 2, size.width(), |
| 86 size.height()); | 87 size.height()); |
| 87 widget_->SetBounds(bounds); | 88 widget_->SetBounds(bounds); |
| 88 | 89 |
| 89 // The widget will be shown when the web contents gets ready to display. | 90 // The widget will be shown when the web contents gets ready to display. |
| 90 return widget_; | 91 return widget_; |
| 91 } | 92 } |
| 92 | 93 |
| 93 ui::ModalType KeyboardOverlayDelegate::GetDialogModalType() const { | 94 ui::ModalType KeyboardOverlayDelegate::GetDialogModalType() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 104 | 105 |
| 105 void KeyboardOverlayDelegate::GetWebUIMessageHandlers( | 106 void KeyboardOverlayDelegate::GetWebUIMessageHandlers( |
| 106 std::vector<WebUIMessageHandler*>* handlers) const { | 107 std::vector<WebUIMessageHandler*>* handlers) const { |
| 107 handlers->push_back(new PaintMessageHandler(widget_)); | 108 handlers->push_back(new PaintMessageHandler(widget_)); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void KeyboardOverlayDelegate::GetDialogSize(gfx::Size* size) const { | 111 void KeyboardOverlayDelegate::GetDialogSize(gfx::Size* size) const { |
| 111 using std::min; | 112 using std::min; |
| 112 DCHECK(widget_); | 113 DCHECK(widget_); |
| 113 gfx::Rect rect = display::Screen::GetScreen() | 114 gfx::Rect rect = display::Screen::GetScreen() |
| 114 ->GetDisplayNearestWindow(widget_->GetNativeView()) | 115 ->GetDisplayNearestWindow(widget_->GetNativeWindow()) |
| 115 .work_area(); | 116 .work_area(); |
| 116 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); | 117 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); |
| 117 const int height = width * kBaseHeight / kBaseWidth; | 118 const int height = width * kBaseHeight / kBaseWidth; |
| 118 size->SetSize(width, height); | 119 size->SetSize(width, height); |
| 119 } | 120 } |
| 120 | 121 |
| 121 std::string KeyboardOverlayDelegate::GetDialogArgs() const { | 122 std::string KeyboardOverlayDelegate::GetDialogArgs() const { |
| 122 return "[]"; | 123 return "[]"; |
| 123 } | 124 } |
| 124 | 125 |
| 125 void KeyboardOverlayDelegate::OnDialogClosed(const std::string& json_retval) { | 126 void KeyboardOverlayDelegate::OnDialogClosed(const std::string& json_retval) { |
| 126 delete this; | 127 delete this; |
| 127 return; | 128 return; |
| 128 } | 129 } |
| 129 | 130 |
| 130 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, | 131 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, |
| 131 bool* out_close_dialog) {} | 132 bool* out_close_dialog) {} |
| 132 | 133 |
| 133 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { | 134 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { |
| 134 return false; | 135 return false; |
| 135 } | 136 } |
| 136 | 137 |
| 137 bool KeyboardOverlayDelegate::HandleContextMenu( | 138 bool KeyboardOverlayDelegate::HandleContextMenu( |
| 138 const content::ContextMenuParams& params) { | 139 const content::ContextMenuParams& params) { |
| 139 return true; | 140 return true; |
| 140 } | 141 } |
| 141 | 142 |
| 142 } // namespace ash | 143 } // namespace ash |
| OLD | NEW |