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->child_at(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( | |
34 Profile* profile, Browser* browser, const GURL& url) | |
35 : dom_view_(new DOMView), | |
36 ALLOW_THIS_IN_INITIALIZER_LIST( | |
37 extension_function_dispatcher_(profile, this)), | |
38 browser_(browser) { | |
39 const GURL keyboard_url( | |
40 url.is_valid() ? url : GURL(chrome::kChromeUIKeyboardURL)); | |
41 dom_view_->Init(profile, | |
42 SiteInstance::CreateSiteInstanceForURL(profile, keyboard_url)); | |
43 dom_view_->LoadURL(keyboard_url); | |
44 | |
45 dom_view_->SetVisible(true); | |
46 AddChildView(dom_view_); | |
47 | |
48 // We have Inited the dom_view. So we must have a tab contents. | |
49 Observe(dom_view_->tab_contents()); | |
50 } | |
51 | |
52 KeyboardContainerView::~KeyboardContainerView() { | |
53 } | |
54 | |
55 std::string KeyboardContainerView::GetClassName() const { | |
56 return kViewClassName; | |
57 } | |
58 | |
59 void KeyboardContainerView::Layout() { | |
60 // TODO(bryeung): include a border between the keyboard and the client view | |
61 dom_view_->SetBounds(0, 0, width(), height()); | |
62 } | |
63 | |
64 void KeyboardContainerView::LoadURL(const GURL& keyboard_url) { | |
65 dom_view_->LoadURL(keyboard_url); | |
66 } | |
67 | |
68 Browser* KeyboardContainerView::GetBrowser() { | |
69 return browser_; | |
70 } | |
71 | |
72 gfx::NativeView KeyboardContainerView::GetNativeViewOfHost() { | |
73 return dom_view_->native_view(); | |
74 } | |
75 | |
76 TabContents* KeyboardContainerView::GetAssociatedTabContents() const { | |
77 return dom_view_->tab_contents(); | |
78 } | |
79 | |
80 void KeyboardContainerView::ViewHierarchyChanged(bool is_add, | |
81 View* parent, | |
82 View* child) { | |
83 if (is_add && Contains(child)) | |
84 MakeViewHierarchyUnfocusable(child); | |
85 } | |
86 | |
87 bool KeyboardContainerView::OnMessageReceived(const IPC::Message& message) { | |
88 bool handled = true; | |
89 IPC_BEGIN_MESSAGE_MAP(KeyboardContainerView, message) | |
90 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
91 IPC_MESSAGE_UNHANDLED(handled = false) | |
92 IPC_END_MESSAGE_MAP() | |
93 return handled; | |
94 } | |
95 | |
96 void KeyboardContainerView::OnRequest( | |
97 const ExtensionHostMsg_Request_Params& request) { | |
98 extension_function_dispatcher_.Dispatch(request, | |
99 dom_view_->tab_contents()->render_view_host()); | |
100 } | |
OLD | NEW |