OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/tab_contents/tab_contents_container.h" | 5 #include "chrome/browser/views/tab_contents/tab_contents_container.h" |
6 | 6 |
7 #include "chrome/browser/tab_contents/interstitial_page.h" | 7 #include "chrome/browser/tab_contents/interstitial_page.h" |
8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
9 #include "chrome/browser/view_ids.h" | 9 #include "chrome/browser/view_ids.h" |
10 #include "chrome/browser/views/tab_contents/native_tab_contents_container.h" | 10 #include "chrome/browser/views/tab_contents/native_tab_contents_container.h" |
11 #include "chrome/common/notification_service.h" | 11 #include "chrome/common/notification_service.h" |
12 | 12 |
13 #if defined(TOUCH_UI) | |
14 #include "chrome/browser/views/tab_contents/native_tab_contents_container_gtk.h" | |
15 #include "chrome/browser/views/tab_contents/tab_contents_view_views.h" | |
16 #include "views/border.h" | |
17 #include "views/fill_layout.h" | |
18 #endif | |
19 | |
13 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
14 // TabContentsContainer, public: | 21 // TabContentsContainer, public: |
15 | 22 |
16 TabContentsContainer::TabContentsContainer() | 23 TabContentsContainer::TabContentsContainer() |
17 : native_container_(NULL), | 24 : native_container_(NULL), |
18 tab_contents_(NULL) { | 25 tab_contents_(NULL) { |
19 SetID(VIEW_ID_TAB_CONTAINER); | 26 SetID(VIEW_ID_TAB_CONTAINER); |
20 } | 27 } |
21 | 28 |
22 TabContentsContainer::~TabContentsContainer() { | 29 TabContentsContainer::~TabContentsContainer() { |
23 if (tab_contents_) | 30 if (tab_contents_) |
24 RemoveObservers(); | 31 RemoveObservers(); |
25 } | 32 } |
26 | 33 |
27 void TabContentsContainer::ChangeTabContents(TabContents* contents) { | 34 void TabContentsContainer::ChangeTabContents(TabContents* contents) { |
28 if (tab_contents_) { | 35 if (tab_contents_) { |
36 #if !defined(TOUCH_UI) | |
29 native_container_->DetachContents(tab_contents_); | 37 native_container_->DetachContents(tab_contents_); |
38 #endif | |
30 tab_contents_->WasHidden(); | 39 tab_contents_->WasHidden(); |
31 RemoveObservers(); | 40 RemoveObservers(); |
32 } | 41 } |
33 tab_contents_ = contents; | 42 tab_contents_ = contents; |
34 // When detaching the last tab of the browser ChangeTabContents is invoked | 43 // When detaching the last tab of the browser ChangeTabContents is invoked |
35 // with NULL. Don't attempt to do anything in that case. | 44 // with NULL. Don't attempt to do anything in that case. |
36 if (tab_contents_) { | 45 if (tab_contents_) { |
46 #if defined(TOUCH_UI) | |
47 views::View *v = (TabContentsViewViews*)contents->view(); | |
oshima
2010/11/08 20:59:38
static_cast
| |
48 // Guard against re-adding ourselves, which happens because the NULL | |
49 // value is ignored by the pre-existing if() above. | |
50 if (v->GetParent() != this) { | |
51 AddChildView(v); | |
52 } | |
53 SetLayoutManager(new views::FillLayout()); | |
54 Layout(); | |
oshima
2010/11/08 20:59:38
do you need to set layout manager everytime?
Also
Alex Nicolaou
2010/11/12 04:05:00
I moved these into the if(...)
Probably I don't n
| |
55 #else | |
37 native_container_->AttachContents(tab_contents_); | 56 native_container_->AttachContents(tab_contents_); |
57 #endif | |
38 AddObservers(); | 58 AddObservers(); |
39 } | 59 } |
40 } | 60 } |
41 | 61 |
42 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { | 62 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { |
43 native_container_->TabContentsFocused(tab_contents); | 63 if (native_container_) |
64 native_container_->TabContentsFocused(tab_contents); | |
44 } | 65 } |
45 | 66 |
46 void TabContentsContainer::SetFastResize(bool fast_resize) { | 67 void TabContentsContainer::SetFastResize(bool fast_resize) { |
47 native_container_->SetFastResize(fast_resize); | 68 if (native_container_) |
69 native_container_->SetFastResize(fast_resize); | |
48 } | 70 } |
49 | 71 |
50 //////////////////////////////////////////////////////////////////////////////// | 72 //////////////////////////////////////////////////////////////////////////////// |
51 // TabContentsContainer, NotificationObserver implementation: | 73 // TabContentsContainer, NotificationObserver implementation: |
52 | 74 |
53 void TabContentsContainer::Observe(NotificationType type, | 75 void TabContentsContainer::Observe(NotificationType type, |
54 const NotificationSource& source, | 76 const NotificationSource& source, |
55 const NotificationDetails& details) { | 77 const NotificationDetails& details) { |
56 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { | 78 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { |
57 RenderViewHostSwitchedDetails* switched_details = | 79 RenderViewHostSwitchedDetails* switched_details = |
58 Details<RenderViewHostSwitchedDetails>(details).ptr(); | 80 Details<RenderViewHostSwitchedDetails>(details).ptr(); |
59 RenderViewHostChanged(switched_details->old_host, | 81 RenderViewHostChanged(switched_details->old_host, |
60 switched_details->new_host); | 82 switched_details->new_host); |
61 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { | 83 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { |
62 TabContentsDestroyed(Source<TabContents>(source).ptr()); | 84 TabContentsDestroyed(Source<TabContents>(source).ptr()); |
63 } else { | 85 } else { |
64 NOTREACHED(); | 86 NOTREACHED(); |
65 } | 87 } |
66 } | 88 } |
67 | 89 |
68 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
69 // TabContentsContainer, View overrides: | 91 // TabContentsContainer, View overrides: |
70 | 92 |
71 void TabContentsContainer::Layout() { | 93 void TabContentsContainer::Layout() { |
94 #if defined(TOUCH_UI) | |
95 views::View::Layout(); | |
96 #else | |
72 if (native_container_) { | 97 if (native_container_) { |
73 native_container_->GetView()->SetBounds(0, 0, width(), height()); | 98 native_container_->GetView()->SetBounds(0, 0, width(), height()); |
74 native_container_->GetView()->Layout(); | 99 native_container_->GetView()->Layout(); |
75 } | 100 } |
101 #endif | |
76 } | 102 } |
77 | 103 |
78 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() { | 104 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() { |
79 return AccessibilityTypes::ROLE_WINDOW; | 105 return AccessibilityTypes::ROLE_WINDOW; |
80 } | 106 } |
81 | 107 |
82 void TabContentsContainer::ViewHierarchyChanged(bool is_add, | 108 void TabContentsContainer::ViewHierarchyChanged(bool is_add, |
83 views::View* parent, | 109 views::View* parent, |
84 views::View* child) { | 110 views::View* child) { |
111 #if defined(TOUCH_UI) | |
112 views::View::ViewHierarchyChanged(is_add, parent, child); | |
113 #else | |
85 if (is_add && child == this) { | 114 if (is_add && child == this) { |
86 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this); | 115 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this); |
87 AddChildView(native_container_->GetView()); | 116 AddChildView(native_container_->GetView()); |
88 } | 117 } |
118 #endif | |
89 } | 119 } |
90 | 120 |
91 //////////////////////////////////////////////////////////////////////////////// | 121 //////////////////////////////////////////////////////////////////////////////// |
92 // TabContentsContainer, private: | 122 // TabContentsContainer, private: |
93 | 123 |
94 void TabContentsContainer::AddObservers() { | 124 void TabContentsContainer::AddObservers() { |
95 // TabContents can change their RenderViewHost and hence the HWND that is | 125 // TabContents can change their RenderViewHost and hence the HWND that is |
96 // shown and getting focused. We need to keep track of that so we install | 126 // shown and getting focused. We need to keep track of that so we install |
97 // the focus subclass on the shown HWND so we intercept focus change events. | 127 // the focus subclass on the shown HWND so we intercept focus change events. |
98 registrar_.Add(this, | 128 registrar_.Add(this, |
99 NotificationType::RENDER_VIEW_HOST_CHANGED, | 129 NotificationType::RENDER_VIEW_HOST_CHANGED, |
100 Source<NavigationController>(&tab_contents_->controller())); | 130 Source<NavigationController>(&tab_contents_->controller())); |
101 | 131 |
102 registrar_.Add(this, | 132 registrar_.Add(this, |
103 NotificationType::TAB_CONTENTS_DESTROYED, | 133 NotificationType::TAB_CONTENTS_DESTROYED, |
104 Source<TabContents>(tab_contents_)); | 134 Source<TabContents>(tab_contents_)); |
105 } | 135 } |
106 | 136 |
107 void TabContentsContainer::RemoveObservers() { | 137 void TabContentsContainer::RemoveObservers() { |
108 registrar_.RemoveAll(); | 138 registrar_.RemoveAll(); |
109 } | 139 } |
110 | 140 |
111 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, | 141 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, |
112 RenderViewHost* new_host) { | 142 RenderViewHost* new_host) { |
143 #if defined(TOUCH_UI) | |
144 NOTIMPLEMENTED(); // TODO(anicolao) | |
145 #else | |
113 native_container_->RenderViewHostChanged(old_host, new_host); | 146 native_container_->RenderViewHostChanged(old_host, new_host); |
147 #endif | |
114 } | 148 } |
115 | 149 |
116 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) { | 150 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) { |
117 // Sometimes, a TabContents is destroyed before we know about it. This allows | 151 // Sometimes, a TabContents is destroyed before we know about it. This allows |
118 // us to clean up our state in case this happens. | 152 // us to clean up our state in case this happens. |
119 DCHECK(contents == tab_contents_); | 153 DCHECK(contents == tab_contents_); |
120 ChangeTabContents(NULL); | 154 ChangeTabContents(NULL); |
121 } | 155 } |
OLD | NEW |