Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/views/keyboard_overlay_delegate.h"
      6 
      7 #include <algorithm>
      8 
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/utf_string_conversions.h"
     11 #include "chrome/browser/ui/views/html_dialog_view.h"
     12 #include "chrome/browser/ui/webui/html_dialog_ui.h"
     13 #include "chrome/common/url_constants.h"
     14 #include "grit/generated_resources.h"
     15 #include "ui/base/l10n/l10n_util.h"
     16 #include "views/screen.h"
     17 
     18 
     19 static const int kBaseWidth = 1252;
     20 static const int kBaseHeight = 516;
     21 static const int kHorizontalMargin = 28;
     22 
     23 KeyboardOverlayDelegate::KeyboardOverlayDelegate(
     24     const std::wstring& title)
     25     : title_(title),
     26       view_(NULL) {
     27 }
     28 
     29 KeyboardOverlayDelegate::~KeyboardOverlayDelegate() {
     30 }
     31 
     32 bool KeyboardOverlayDelegate::IsDialogModal() const {
     33   return true;
     34 }
     35 
     36 std::wstring KeyboardOverlayDelegate::GetDialogTitle() const {
     37   return title_;
     38 }
     39 
     40 GURL KeyboardOverlayDelegate::GetDialogContentURL() const {
     41   std::string url_string(chrome::kChromeUIKeyboardOverlayURL);
     42   return GURL(url_string);
     43 }
     44 
     45 void KeyboardOverlayDelegate::GetWebUIMessageHandlers(
     46     std::vector<WebUIMessageHandler*>* handlers) const {
     47 }
     48 
     49 void KeyboardOverlayDelegate::GetDialogSize(
     50     gfx::Size* size) const {
     51   using std::min;
     52   DCHECK(view_);
     53   gfx::Rect rect = views::Screen::GetMonitorAreaNearestWindow(
     54       view_->native_view());
     55   const int width = min(kBaseWidth, rect.width() - kHorizontalMargin);
     56   const int height = width * kBaseHeight / kBaseWidth;
     57   size->SetSize(width, height);
     58 }
     59 
     60 std::string KeyboardOverlayDelegate::GetDialogArgs() const {
     61   return "[]";
     62 }
     63 
     64 void KeyboardOverlayDelegate::OnDialogClosed(
     65     const std::string& json_retval) {
     66   delete this;
     67   return;
     68 }
     69 
     70 void KeyboardOverlayDelegate::OnCloseContents(TabContents* source,
     71                                               bool* out_close_dialog) {
     72 }
     73 
     74 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const {
     75   return false;
     76 }
     77 
     78 bool KeyboardOverlayDelegate::HandleContextMenu(
     79     const ContextMenuParams& params) {
     80   return true;
     81 }
     82