Chromium Code Reviews

Side by Side Diff: chrome/browser/ui/touch/frame/touch_browser_frame_view.cc

Issue 5747001: Add the virtual keyboard to BrowserFrameChromeos. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean-up Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/touch/frame/touch_browser_frame_view.h"
6
7 #include <algorithm>
8
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/renderer_host/site_instance.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/views/dom_view.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/common/notification_service.h"
15 #include "chrome/common/notification_type.h"
16 #include "chrome/common/url_constants.h"
17 #include "gfx/rect.h"
18
19 namespace {
20
21 const int kKeyboardHeight = 300;
22
23 } // namespace
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // TouchBrowserFrameView, public:
27
28 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame,
29 BrowserView* browser_view)
30 : OpaqueBrowserFrameView(frame, browser_view),
31 keyboard_(NULL) {
32 registrar_.Add(this,
33 NotificationType::NAV_ENTRY_COMMITTED,
34 NotificationService::AllSources());
35 registrar_.Add(this,
36 NotificationType::FOCUS_CHANGED_IN_PAGE,
37 NotificationService::AllSources());
38 }
39
40 TouchBrowserFrameView::~TouchBrowserFrameView() {
41 }
42
43 ///////////////////////////////////////////////////////////////////////////////
44 // TouchBrowserFrameView, protected:
45 int TouchBrowserFrameView::GetReservedHeight() const {
46 if (keyboard_ && keyboard_->IsVisible()) {
47 return kKeyboardHeight;
48 }
49 return 0;
50 }
51
52 ///////////////////////////////////////////////////////////////////////////////
53 // TouchBrowserFrameView, private:
54
55 void TouchBrowserFrameView::InitVirtualKeyboard() {
56 if (keyboard_)
57 return;
58
59 keyboard_ = new DOMView;
60
61 Profile* keyboard_profile = browser_view()->browser()->profile();
62 DCHECK(keyboard_profile) << "Profile required for virtual keyboard.";
63
64 GURL keyboard_url(chrome::kChromeUIKeyboardURL);
65 keyboard_->Init(keyboard_profile,
66 SiteInstance::CreateSiteInstanceForURL(keyboard_profile, keyboard_url));
67 keyboard_->LoadURL(keyboard_url);
68
69 keyboard_->SetVisible(false);
70 AddChildView(keyboard_);
71 }
72
73 void TouchBrowserFrameView::UpdateKeyboardAndLayout(bool should_show_keyboard) {
74 // If we have not created the keyboard yet, then we can safely skip
sky 2010/12/10 18:18:20 Wouldn't it be better to have this method call Ini
bryeung 2010/12/10 23:58:59 If we try to InitVirtualKeyboard too early, it wil
sky 2010/12/13 17:37:37 My comment wasn't very good. I'm suggesting you ma
75 // this method as must be trying to hide it.
76 if (!keyboard_) {
77 DCHECK(!should_show_keyboard);
78 return;
79 }
80
81 if (should_show_keyboard == keyboard_->IsVisible())
82 return;
83
84 keyboard_->SetVisible(should_show_keyboard);
85
86 // Because the NonClientFrameView is a sibling of the ClientView,
87 // we rely on the parent to properly resize the ClientView.
88 GetParent()->Layout();
89 }
90
91 void TouchBrowserFrameView::Observe(NotificationType type,
92 const NotificationSource& source,
93 const NotificationDetails& details) {
94 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) {
95 InitVirtualKeyboard();
96 UpdateKeyboardAndLayout(*Details<const bool>(details).ptr());
sky 2010/12/10 18:18:20 You're going to support multiple windows, right? Y
bryeung 2010/12/10 23:58:59 TOUCH_UI will not support multiple windows.
sky 2010/12/13 17:37:37 Remember that panels/popups are also browser windo
97 } else {
98 DCHECK(type == NotificationType::NAV_ENTRY_COMMITTED);
99
100 // TODO(bryeung): this is hiding the keyboard for the very first page
101 // load after browser startup when the page has an input element focused
102 // to start with. It would be nice to fix, but not critical.
103
104 // Everything else we have registered for should hide the keyboard.
105 UpdateKeyboardAndLayout(false);
106 }
107 }
OLDNEW

Powered by Google App Engine