OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/views/dom_view.h" | 5 #include "chrome/browser/views/dom_view.h" |
6 | 6 |
7 #include "chrome/browser/tab_contents/tab_contents.h" | 7 #include "chrome/browser/tab_contents/tab_contents.h" |
8 #include "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
9 #include "views/focus/focus_manager.h" | 9 #include "views/focus/focus_manager.h" |
10 | 10 |
| 11 #if defined(TOUCH_UI) |
| 12 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" |
| 13 #endif |
| 14 |
11 DOMView::DOMView() : tab_contents_(NULL), initialized_(false) { | 15 DOMView::DOMView() : tab_contents_(NULL), initialized_(false) { |
12 SetFocusable(true); | 16 SetFocusable(true); |
13 } | 17 } |
14 | 18 |
15 DOMView::~DOMView() { | 19 DOMView::~DOMView() { |
16 if (native_view()) | 20 if (native_view()) |
17 Detach(); | 21 Detach(); |
18 } | 22 } |
19 | 23 |
20 bool DOMView::Init(Profile* profile, SiteInstance* instance) { | 24 bool DOMView::Init(Profile* profile, SiteInstance* instance) { |
21 if (initialized_) | 25 if (initialized_) |
22 return true; | 26 return true; |
23 | 27 |
24 initialized_ = true; | 28 initialized_ = true; |
25 tab_contents_.reset(CreateTabContents(profile, instance)); | 29 tab_contents_.reset(CreateTabContents(profile, instance)); |
26 // Attach the native_view now if the view is already added to Widget. | 30 // Attach the native_view now if the view is already added to Widget. |
27 if (GetWidget()) | 31 if (GetWidget()) |
28 Attach(tab_contents_->GetNativeView()); | 32 AttachTabContents(); |
29 return true; | 33 return true; |
30 } | 34 } |
31 | 35 |
32 TabContents* DOMView::CreateTabContents(Profile* profile, | 36 TabContents* DOMView::CreateTabContents(Profile* profile, |
33 SiteInstance* instance) { | 37 SiteInstance* instance) { |
34 return new TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL); | 38 return new TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL); |
35 } | 39 } |
36 | 40 |
37 void DOMView::LoadURL(const GURL& url) { | 41 void DOMView::LoadURL(const GURL& url) { |
38 DCHECK(initialized_); | 42 DCHECK(initialized_); |
(...skipping 10 matching lines...) Expand all Loading... |
49 void DOMView::Focus() { | 53 void DOMView::Focus() { |
50 tab_contents_->Focus(); | 54 tab_contents_->Focus(); |
51 } | 55 } |
52 | 56 |
53 void DOMView::ViewHierarchyChanged(bool is_add, views::View* parent, | 57 void DOMView::ViewHierarchyChanged(bool is_add, views::View* parent, |
54 views::View* child) { | 58 views::View* child) { |
55 // Attach the native_view when this is added to Widget if | 59 // Attach the native_view when this is added to Widget if |
56 // the native view has not been attached yet and tab_contents_ exists. | 60 // the native view has not been attached yet and tab_contents_ exists. |
57 views::NativeViewHost::ViewHierarchyChanged(is_add, parent, child); | 61 views::NativeViewHost::ViewHierarchyChanged(is_add, parent, child); |
58 if (is_add && GetWidget() && !native_view() && tab_contents_.get()) | 62 if (is_add && GetWidget() && !native_view() && tab_contents_.get()) |
59 Attach(tab_contents_->GetNativeView()); | 63 AttachTabContents(); |
60 else if (!is_add && child == this && native_view()) | 64 else if (!is_add && child == this && native_view()) |
61 Detach(); | 65 Detach(); |
62 } | 66 } |
| 67 |
| 68 void DOMView::AttachTabContents() { |
| 69 #if defined(TOUCH_UI) |
| 70 AttachToView(static_cast<TabContentsViewViews*>(tab_contents_->view())); |
| 71 #else |
| 72 Attach(tab_contents_->GetNativeView()); |
| 73 #endif |
| 74 } |
OLD | NEW |