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/views/dom_view.h"
9#include "chrome/common/url_constants.h"
10#include "content/browser/site_instance.h"
11
12namespace {
13
14// Make the provided view and all of its descendents unfocusable.
15void MakeViewHierarchyUnfocusable(views::View* view) {
16  view->SetFocusable(false);
17  for (int i = 0; i < view->child_count(); ++i) {
18    MakeViewHierarchyUnfocusable(view->GetChildViewAt(i));
19  }
20}
21
22}  // namepsace
23
24///////////////////////////////////////////////////////////////////////////////
25// KeyboardContainerView, public:
26
27KeyboardContainerView::KeyboardContainerView(Profile* profile)
28    : dom_view_(new DOMView) {
29  GURL keyboard_url(chrome::kChromeUIKeyboardURL);
30  dom_view_->Init(profile,
31      SiteInstance::CreateSiteInstanceForURL(profile, keyboard_url));
32  dom_view_->LoadURL(keyboard_url);
33
34  dom_view_->SetVisible(true);
35  AddChildView(dom_view_);
36}
37
38KeyboardContainerView::~KeyboardContainerView() {
39}
40
41void KeyboardContainerView::Layout() {
42  // TODO(bryeung): include a border between the keyboard and the client view
43  dom_view_->SetBounds(0, 0, width(), height());
44}
45
46void KeyboardContainerView::ViewHierarchyChanged(bool is_add,
47                                                 View* parent,
48                                                 View* child) {
49  if (is_add)
50    MakeViewHierarchyUnfocusable(child);
51}
52