diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 21:55:02 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-25 21:55:02 +0000 |
commit | 729b4851c4a3dc59e40f80b8798fa9253ee074a0 (patch) | |
tree | d0b8a1f468a3b20ca3df0ba56286e83ca9564686 /ash/keyboard_overlay/keyboard_overlay_delegate.cc | |
parent | 16b7b2781d20602e7b58eaaf23a3c6e6ac250a55 (diff) | |
download | chromium_src-729b4851c4a3dc59e40f80b8798fa9253ee074a0.zip chromium_src-729b4851c4a3dc59e40f80b8798fa9253ee074a0.tar.gz chromium_src-729b4851c4a3dc59e40f80b8798fa9253ee074a0.tar.bz2 |
Revert "Revert 148383 - Move the keyboard overlay view to ash."
The original CL broke win_aura, which is fixed in this CL.
This reverts commit b36e66174d685a4195d7cc934d978086e033a8c4.
TBR=ben@chromium.org
BUG=124222
TEST=None
Review URL: https://chromiumcodereview.appspot.com/10824023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148428 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/keyboard_overlay/keyboard_overlay_delegate.cc')
-rw-r--r-- | ash/keyboard_overlay/keyboard_overlay_delegate.cc | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/ash/keyboard_overlay/keyboard_overlay_delegate.cc b/ash/keyboard_overlay/keyboard_overlay_delegate.cc new file mode 100644 index 0000000..e819a98 --- /dev/null +++ b/ash/keyboard_overlay/keyboard_overlay_delegate.cc @@ -0,0 +1,143 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/keyboard_overlay/keyboard_overlay_delegate.h" + +#include <algorithm> + +#include "base/bind.h" +#include "base/memory/weak_ptr.h" +#include "base/utf_string_conversions.h" +#include "base/values.h" +#include "content/public/browser/web_ui.h" +#include "content/public/browser/web_ui_message_handler.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/screen.h" +#include "ui/views/controls/webview/web_dialog_view.h" +#include "ui/views/widget/widget.h" + +using content::WebContents; +using content::WebUIMessageHandler; + +namespace { + +const int kBaseWidth = 1252; +const int kBaseHeight = 516; +const int kHorizontalMargin = 28; + +// A message handler for detecting the timing when the web contents is painted. +class PaintMessageHandler + : public WebUIMessageHandler, + public base::SupportsWeakPtr<PaintMessageHandler> { + public: + explicit PaintMessageHandler(views::Widget* widget) : widget_(widget) {} + virtual ~PaintMessageHandler() {} + + // WebUIMessageHandler implementation. + virtual void RegisterMessages() OVERRIDE; + + private: + void DidPaint(const ListValue* args); + + views::Widget* widget_; + + DISALLOW_COPY_AND_ASSIGN(PaintMessageHandler); +}; + +void PaintMessageHandler::RegisterMessages() { + web_ui()->RegisterMessageCallback( + "didPaint", + base::Bind(&PaintMessageHandler::DidPaint, base::Unretained(this))); +} + +void PaintMessageHandler::DidPaint(const ListValue* args) { + // Show the widget after the web content has been painted. + widget_->Show(); +} + +} // namespace + +KeyboardOverlayDelegate::KeyboardOverlayDelegate(const string16& title, + const GURL& url) + : title_(title), + url_(url), + view_(NULL) { +} + +KeyboardOverlayDelegate::~KeyboardOverlayDelegate() { +} + +void KeyboardOverlayDelegate::Show(views::WebDialogView* view) { + view_ = view; + + views::Widget* widget = new views::Widget; + views::Widget::InitParams params( + views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); + params.delegate = view; + widget->Init(params); + + // Show the widget at the bottom of the work area. + gfx::Size size; + GetDialogSize(&size); + const gfx::Rect& rect = gfx::Screen::GetDisplayNearestWindow( + widget->GetNativeView()).work_area(); + gfx::Rect bounds((rect.width() - size.width()) / 2, + rect.height() - size.height(), + size.width(), + size.height()); + widget->SetBounds(bounds); + + // The widget will be shown when the web contents gets ready to display. +} + +ui::ModalType KeyboardOverlayDelegate::GetDialogModalType() const { + return ui::MODAL_TYPE_SYSTEM; +} + +string16 KeyboardOverlayDelegate::GetDialogTitle() const { + return title_; +} + +GURL KeyboardOverlayDelegate::GetDialogContentURL() const { + return url_; +} + +void KeyboardOverlayDelegate::GetWebUIMessageHandlers( + std::vector<WebUIMessageHandler*>* handlers) const { + handlers->push_back(new PaintMessageHandler(view_->GetWidget())); +} + +void KeyboardOverlayDelegate::GetDialogSize( + gfx::Size* size) const { + using std::min; + DCHECK(view_); + gfx::Rect rect = gfx::Screen::GetDisplayNearestWindow( + view_->GetWidget()->GetNativeView()).bounds(); + const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); + const int height = width * kBaseHeight / kBaseWidth; + size->SetSize(width, height); +} + +std::string KeyboardOverlayDelegate::GetDialogArgs() const { + return "[]"; +} + +void KeyboardOverlayDelegate::OnDialogClosed( + const std::string& json_retval) { + delete this; + return; +} + +void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, + bool* out_close_dialog) { +} + +bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { + return false; +} + +bool KeyboardOverlayDelegate::HandleContextMenu( + const content::ContextMenuParams& params) { + return true; +} |