Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/browser/ui/views/keyboard_overlay_delegate.cc

Issue 10442044: Fix the white flicker of the keyboard overlay when it first appearing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/ui/views/keyboard_overlay_delegate.h" 5 #include "chrome/browser/ui/views/keyboard_overlay_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/views/web_dialog_view.h" 10 #include "chrome/browser/ui/views/keyboard_overlay_dialog_view.h"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "content/public/browser/notification_source.h"
13 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/render_widget_host.h"
16 #include "content/public/browser/web_contents.h"
12 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
13 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/gfx/screen.h" 20 #include "ui/gfx/screen.h"
16 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
17 22
18 using content::WebContents; 23 using content::WebContents;
19 using content::WebUIMessageHandler; 24 using content::WebUIMessageHandler;
20 25
21 namespace { 26 namespace {
22 27
23 const int kBaseWidth = 1252; 28 const int kBaseWidth = 1252;
24 const int kBaseHeight = 516; 29 const int kBaseHeight = 516;
25 const int kHorizontalMargin = 28; 30 const int kHorizontalMargin = 28;
26 31
27 } // namespace 32 } // namespace
28 33
29 KeyboardOverlayDelegate::KeyboardOverlayDelegate(const string16& title) 34 KeyboardOverlayDelegate::KeyboardOverlayDelegate(const string16& title)
30 : title_(title), 35 : title_(title),
31 view_(NULL) { 36 view_(NULL),
37 loaded_(false) {
32 } 38 }
33 39
34 KeyboardOverlayDelegate::~KeyboardOverlayDelegate() { 40 KeyboardOverlayDelegate::~KeyboardOverlayDelegate() {
35 } 41 }
36 42
43 void KeyboardOverlayDelegate::Show(KeyboardOverlayDialogView* view) {
44 view_ = view;
45
46 views::Widget* widget = new views::Widget;
47 views::Widget::InitParams params(
48 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
49 params.delegate = view;
50 widget->Init(params);
51
52 // Show the widget at the bottom of the work area.
53 gfx::Size size;
54 GetDialogSize(&size);
55 gfx::Rect rect = gfx::Screen::GetMonitorNearestWindow(
oshima 2012/05/25 22:33:20 const gfx::Rect&
mazda 2012/05/25 23:30:37 Done.
56 widget->GetNativeView()).work_area();
57 gfx::Rect bounds((rect.width() - size.width()) / 2,
58 rect.height() - size.height(),
59 size.width(),
60 size.height());
61 widget->SetBounds(bounds);
62
63 widget->Show();
64
65 // Make the widget invisible until the web contents gets ready to display.
66 widget->SetOpacity(0);
67 }
68
37 ui::ModalType KeyboardOverlayDelegate::GetDialogModalType() const { 69 ui::ModalType KeyboardOverlayDelegate::GetDialogModalType() const {
38 return ui::MODAL_TYPE_SYSTEM; 70 return ui::MODAL_TYPE_SYSTEM;
39 } 71 }
40 72
41 string16 KeyboardOverlayDelegate::GetDialogTitle() const { 73 string16 KeyboardOverlayDelegate::GetDialogTitle() const {
42 return title_; 74 return title_;
43 } 75 }
44 76
45 GURL KeyboardOverlayDelegate::GetDialogContentURL() const { 77 GURL KeyboardOverlayDelegate::GetDialogContentURL() const {
46 std::string url_string(chrome::kChromeUIKeyboardOverlayURL); 78 std::string url_string(chrome::kChromeUIKeyboardOverlayURL);
(...skipping 12 matching lines...) Expand all
59 view_->GetWidget()->GetNativeView()).bounds(); 91 view_->GetWidget()->GetNativeView()).bounds();
60 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); 92 const int width = min(kBaseWidth, rect.width() - kHorizontalMargin);
61 const int height = width * kBaseHeight / kBaseWidth; 93 const int height = width * kBaseHeight / kBaseWidth;
62 size->SetSize(width, height); 94 size->SetSize(width, height);
63 } 95 }
64 96
65 std::string KeyboardOverlayDelegate::GetDialogArgs() const { 97 std::string KeyboardOverlayDelegate::GetDialogArgs() const {
66 return "[]"; 98 return "[]";
67 } 99 }
68 100
101 void KeyboardOverlayDelegate::OnDialogShown(
102 content::WebUI* webui,
103 content::RenderViewHost* render_view_host) {
104 registrar_.Add(this,
105 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
106 content::Source<content::WebContents>(
107 webui->GetWebContents()));
108 registrar_.Add(this,
109 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT,
110 content::Source<content::RenderWidgetHost>(render_view_host));
111 }
112
69 void KeyboardOverlayDelegate::OnDialogClosed( 113 void KeyboardOverlayDelegate::OnDialogClosed(
70 const std::string& json_retval) { 114 const std::string& json_retval) {
71 delete this; 115 delete this;
72 return; 116 return;
73 } 117 }
74 118
75 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source, 119 void KeyboardOverlayDelegate::OnCloseContents(WebContents* source,
76 bool* out_close_dialog) { 120 bool* out_close_dialog) {
77 } 121 }
78 122
79 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const { 123 bool KeyboardOverlayDelegate::ShouldShowDialogTitle() const {
80 return false; 124 return false;
81 } 125 }
82 126
83 bool KeyboardOverlayDelegate::HandleContextMenu( 127 bool KeyboardOverlayDelegate::HandleContextMenu(
84 const content::ContextMenuParams& params) { 128 const content::ContextMenuParams& params) {
85 return true; 129 return true;
86 } 130 }
131
132 void KeyboardOverlayDelegate::Observe(
133 int type,
134 const content::NotificationSource& source,
135 const content::NotificationDetails& details) {
136 switch (type) {
137 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME:
138 registrar_.Remove(this,
139 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
140 source);
141 loaded_ = true;
142 break;
143 case content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT:
oshima 2012/05/25 22:33:20 I wonder if we can rely on this notification when
mazda 2012/05/25 23:30:37 Thanks. I'll ask backer.
144 if (!loaded_)
145 break;
146 registrar_.Remove(this,
147 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT,
148 source);
149 view_->GetWidget()->SetOpacity(255);
150 break;
151 default:
152 NOTREACHED() << "Unknown type: " << type;
153 }
154 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/keyboard_overlay_delegate.h ('k') | chrome/browser/ui/views/keyboard_overlay_dialog_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698