OLD | NEW |
---|---|
(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/views/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 /////////////////////////////////////////////////////////////////////////////// | |
20 // TouchBrowserFrameView, public: | |
21 | |
22 TouchBrowserFrameView::TouchBrowserFrameView(BrowserFrame* frame, | |
23 BrowserView* browser_view) | |
24 : OpaqueBrowserFrameView(frame, browser_view) { | |
25 registrar_.Add(this, | |
sky
2010/12/09 22:19:03
initialize keyboard_ to NULL here.
bryeung
2010/12/10 17:23:19
Done.
| |
26 NotificationType::NAV_ENTRY_COMMITTED, | |
27 NotificationService::AllSources()); | |
28 registrar_.Add(this, | |
29 NotificationType::FOCUS_CHANGED_IN_PAGE, | |
30 NotificationService::AllSources()); | |
31 } | |
32 | |
33 TouchBrowserFrameView::~TouchBrowserFrameView() { | |
34 } | |
35 | |
36 void TouchBrowserFrameView::Layout() { | |
37 OpaqueBrowserFrameView::Layout(); | |
38 | |
39 if (keyboard_ && keyboard_->IsVisible()) { | |
40 gfx::Rect* client_view_bounds = this->client_view_bounds(); | |
sky
2010/12/09 22:19:03
Adjusting the height in this manner is subtle and
bryeung
2010/12/10 17:23:19
Done.
| |
41 int keyboard_height = 200; | |
42 client_view_bounds->set_height( | |
43 std::max(0, client_view_bounds->height() - keyboard_height)); | |
44 | |
45 keyboard_->SetBounds(client_view_bounds->x(), | |
46 client_view_bounds->y() + client_view_bounds->height(), | |
47 client_view_bounds->width(), keyboard_height); | |
48 keyboard_->Layout(); | |
49 } | |
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 = GetBrowserView()->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 | |
75 // this method as must be trying to hide it. | |
76 if (!keyboard_) { | |
77 DCHECK(!should_show_keyboard); | |
78 return; | |
79 } | |
80 | |
81 keyboard_->SetVisible(should_show_keyboard); | |
82 Layout(); | |
83 | |
84 // Because the NonClientFrameView is a sibling of the ClientView, | |
85 // we rely on the parent to properly resize the ClientView. | |
86 GetParent()->Layout(); | |
sky
2010/12/09 22:19:03
Shouldn't this result in a Layout on this class to
bryeung
2010/12/10 17:23:19
Yep, you're right. I'll use a smaller hammer :-)
| |
87 } | |
88 | |
89 void TouchBrowserFrameView::Observe(NotificationType type, | |
90 const NotificationSource& source, | |
91 const NotificationDetails& details) { | |
92 if (type == NotificationType::FOCUS_CHANGED_IN_PAGE) { | |
93 InitVirtualKeyboard(); | |
94 const bool is_editable_node = *Details<const bool>(details).ptr(); | |
95 if (is_editable_node != keyboard_->IsVisible()) { | |
sky
2010/12/09 22:19:03
Rather than having the check here, wouldn't it be
bryeung
2010/12/10 17:23:19
Yes: good idea. Done.
| |
96 UpdateKeyboardAndLayout(is_editable_node); | |
97 } | |
98 } else { | |
sky
2010/12/09 22:19:03
You should at least have a DCHECK here on the type
bryeung
2010/12/10 17:23:19
Done.
| |
99 // TODO(bryeung): this is hiding the keyboard for the very first page | |
100 // load after browser startup when the page has an input element focused | |
101 // to start with. It would be nice to fix, but not critical. | |
102 | |
103 // Everything else we have registered for should hide the keyboard. | |
104 UpdateKeyboardAndLayout(false); | |
105 } | |
106 } | |
OLD | NEW |