OLD | NEW |
| (Empty) |
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/touch/frame/keyboard_container_view.h" | |
6 | |
7 #include "chrome/browser/profiles/profile.h" | |
8 #include "chrome/browser/ui/browser.h" | |
9 #include "chrome/browser/ui/views/dom_view.h" | |
10 #include "chrome/common/url_constants.h" | |
11 #include "content/browser/site_instance.h" | |
12 #include "content/browser/tab_contents/tab_contents.h" | |
13 | |
14 namespace { | |
15 | |
16 // Make the provided view and all of its descendents unfocusable. | |
17 void MakeViewHierarchyUnfocusable(views::View* view) { | |
18 view->set_focusable(false); | |
19 for (int i = 0; i < view->child_count(); ++i) { | |
20 MakeViewHierarchyUnfocusable(view->GetChildViewAt(i)); | |
21 } | |
22 } | |
23 | |
24 } // namepsace | |
25 | |
26 // static | |
27 const char KeyboardContainerView::kViewClassName[] = | |
28 "browser/ui/touch/frame/KeyboardContainerView"; | |
29 | |
30 /////////////////////////////////////////////////////////////////////////////// | |
31 // KeyboardContainerView, public: | |
32 | |
33 KeyboardContainerView::KeyboardContainerView(Profile* profile, Browser* browser) | |
34 : dom_view_(new DOMView), | |
35 ALLOW_THIS_IN_INITIALIZER_LIST( | |
36 extension_function_dispatcher_(profile, this)), | |
37 browser_(browser) { | |
38 GURL keyboard_url(chrome::kChromeUIKeyboardURL); | |
39 dom_view_->Init(profile, | |
40 SiteInstance::CreateSiteInstanceForURL(profile, keyboard_url)); | |
41 dom_view_->LoadURL(keyboard_url); | |
42 | |
43 dom_view_->SetVisible(true); | |
44 AddChildView(dom_view_); | |
45 | |
46 // We have Inited the dom_view. So we must have a tab contents. | |
47 Observe(dom_view_->tab_contents()); | |
48 } | |
49 | |
50 KeyboardContainerView::~KeyboardContainerView() { | |
51 } | |
52 | |
53 std::string KeyboardContainerView::GetClassName() const { | |
54 return kViewClassName; | |
55 } | |
56 | |
57 void KeyboardContainerView::Layout() { | |
58 // TODO(bryeung): include a border between the keyboard and the client view | |
59 dom_view_->SetBounds(0, 0, width(), height()); | |
60 } | |
61 | |
62 void KeyboardContainerView::LoadURL(const GURL& keyboard_url) { | |
63 dom_view_->LoadURL(keyboard_url); | |
64 } | |
65 | |
66 Browser* KeyboardContainerView::GetBrowser() { | |
67 return browser_; | |
68 } | |
69 | |
70 gfx::NativeView KeyboardContainerView::GetNativeViewOfHost() { | |
71 return dom_view_->native_view(); | |
72 } | |
73 | |
74 TabContents* KeyboardContainerView::GetAssociatedTabContents() const { | |
75 return dom_view_->tab_contents(); | |
76 } | |
77 | |
78 void KeyboardContainerView::ViewHierarchyChanged(bool is_add, | |
79 View* parent, | |
80 View* child) { | |
81 if (is_add && Contains(child)) | |
82 MakeViewHierarchyUnfocusable(child); | |
83 } | |
84 | |
85 bool KeyboardContainerView::OnMessageReceived(const IPC::Message& message) { | |
86 bool handled = true; | |
87 IPC_BEGIN_MESSAGE_MAP(KeyboardContainerView, message) | |
88 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
89 IPC_MESSAGE_UNHANDLED(handled = false) | |
90 IPC_END_MESSAGE_MAP() | |
91 return handled; | |
92 } | |
93 | |
94 void KeyboardContainerView::OnRequest( | |
95 const ExtensionHostMsg_Request_Params& request) { | |
96 extension_function_dispatcher_.Dispatch(request, | |
97 dom_view_->tab_contents()->render_view_host()); | |
98 } | |
OLD | NEW |