Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: chrome/browser/ui/views/tab_contents/tab_contents_container.cc

Issue 6024007: First cut at creating a refactored version of tab_contents_views. This is (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated the diff using -M1% -B1% to capture the refactoring better Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // For reasons that are as yet unclear to me, all of this "common" code
sky 2011/01/05 16:43:03 Is this comment right?
Ben Goodger (Google) 2011/01/05 17:14:44 I don't believe it is - the TAB_CONTENTS_DESTROYED
Alex Nicolaou 2011/01/06 09:37:17 No sorry this is construction dust from a intermed
2 // is dead code. Left here for cleanup post-refactoring.
Ben Goodger (Google) 2011/01/05 17:14:44 Also, comments like this should go below the licen
Alex Nicolaou 2011/01/06 09:37:17 Sorry this comment will get deleted it's wrong.
3
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 4 // 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 5 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 6 // found in the LICENSE file.
4 7
5 #include "chrome/browser/views/tab_contents/tab_contents_container.h" 8 #include "chrome/browser/views/tab_contents/tab_contents_container.h"
6 9
7 #include "chrome/browser/renderer_host/render_view_host.h" 10 #include "chrome/browser/renderer_host/render_view_host.h"
8 #include "chrome/browser/renderer_host/render_widget_host_view.h" 11 #include "chrome/browser/renderer_host/render_widget_host_view.h"
9 #include "chrome/browser/tab_contents/interstitial_page.h" 12 #include "chrome/browser/tab_contents/interstitial_page.h"
10 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/tab_contents.h"
11 #include "chrome/browser/ui/view_ids.h" 14 #include "chrome/browser/ui/view_ids.h"
12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" 15 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h"
13 #include "chrome/common/notification_details.h" 16 #include "chrome/common/notification_details.h"
14 #include "chrome/common/notification_source.h" 17 #include "chrome/common/notification_source.h"
15 18
16 #if defined(TOUCH_UI)
17 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk .h"
18 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
19 #include "views/border.h"
20 #include "views/fill_layout.h"
21 #endif
22 19
23 //////////////////////////////////////////////////////////////////////////////// 20 ////////////////////////////////////////////////////////////////////////////////
24 // TabContentsContainer, public: 21 // TabContentsContainer, public:
25 22
26 TabContentsContainer::TabContentsContainer()
27 : native_container_(NULL),
28 tab_contents_(NULL),
29 reserved_area_delegate_(NULL) {
30 SetID(VIEW_ID_TAB_CONTAINER);
31 }
32
33 TabContentsContainer::~TabContentsContainer() { 23 TabContentsContainer::~TabContentsContainer() {
34 if (tab_contents_) 24 if (tab_contents_)
35 RemoveObservers(); 25 RemoveObservers();
36 } 26 }
37 27
38 void TabContentsContainer::ChangeTabContents(TabContents* contents) {
39 if (tab_contents_) {
40 #if !defined(TOUCH_UI)
41 native_container_->DetachContents(tab_contents_);
42 #else
43 views::View *v = static_cast<TabContentsViewViews*>(tab_contents_->view());
44 RemoveChildView(v);
45 #endif
46 tab_contents_->WasHidden();
47 RemoveObservers();
48 }
49 #if !defined(TOUCH_UI)
50 TabContents* old_contents = tab_contents_;
51 #endif
52 tab_contents_ = contents;
53 // When detaching the last tab of the browser ChangeTabContents is invoked
54 // with NULL. Don't attempt to do anything in that case.
55 if (tab_contents_) {
56 #if defined(TOUCH_UI)
57 views::View *v = static_cast<TabContentsViewViews*>(contents->view());
58 // Guard against re-adding ourselves, which happens because the NULL
59 // value is ignored by the pre-existing if() above.
60 if (v->GetParent() != this) {
61 AddChildView(v);
62 SetLayoutManager(new views::FillLayout());
63 Layout();
64 }
65 #else
66 RenderWidgetHostViewChanged(
67 old_contents ? old_contents->GetRenderWidgetHostView() : NULL,
68 tab_contents_->GetRenderWidgetHostView());
69 native_container_->AttachContents(tab_contents_);
70 #endif
71 AddObservers();
72 }
73 }
74
75 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) {
76 if (native_container_)
77 native_container_->TabContentsFocused(tab_contents);
78 }
79
80 void TabContentsContainer::SetFastResize(bool fast_resize) {
81 if (native_container_)
82 native_container_->SetFastResize(fast_resize);
83 }
84
85 //////////////////////////////////////////////////////////////////////////////// 28 ////////////////////////////////////////////////////////////////////////////////
86 // TabContentsContainer, NotificationObserver implementation: 29 // TabContentsContainer, NotificationObserver implementation:
87 30
88 void TabContentsContainer::Observe(NotificationType type, 31 void TabContentsContainer::Observe(NotificationType type,
89 const NotificationSource& source, 32 const NotificationSource& source,
90 const NotificationDetails& details) { 33 const NotificationDetails& details) {
91 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { 34 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) {
92 RenderViewHostSwitchedDetails* switched_details = 35 RenderViewHostSwitchedDetails* switched_details =
93 Details<RenderViewHostSwitchedDetails>(details).ptr(); 36 Details<RenderViewHostSwitchedDetails>(details).ptr();
94 RenderViewHostChanged(switched_details->old_host, 37 RenderViewHostChanged(switched_details->old_host,
95 switched_details->new_host); 38 switched_details->new_host);
96 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { 39 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
97 TabContentsDestroyed(Source<TabContents>(source).ptr()); 40 TabContentsDestroyed(Source<TabContents>(source).ptr());
98 } else { 41 } else {
99 NOTREACHED(); 42 NOTREACHED();
100 } 43 }
101 } 44 }
102 45
103 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
104 // TabContentsContainer, View overrides: 47 // TabContentsContainer, View overrides:
105 48
106 void TabContentsContainer::Layout() {
107 #if defined(TOUCH_UI)
108 views::View::Layout();
109 #else
110 if (native_container_) {
111 if (reserved_area_delegate_)
112 reserved_area_delegate_->UpdateReservedContentsRect(this);
113 native_container_->GetView()->SetBounds(0, 0, width(), height());
114 native_container_->GetView()->Layout();
115 }
116 #endif
117 }
118
119 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() { 49 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() {
120 return AccessibilityTypes::ROLE_WINDOW; 50 return AccessibilityTypes::ROLE_WINDOW;
121 } 51 }
122 52
123 void TabContentsContainer::ViewHierarchyChanged(bool is_add,
124 views::View* parent,
125 views::View* child) {
126 #if defined(TOUCH_UI)
127 views::View::ViewHierarchyChanged(is_add, parent, child);
128 #else
129 if (is_add && child == this) {
130 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this);
131 AddChildView(native_container_->GetView());
132 }
133 #endif
134 }
135
136 //////////////////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////////////////
137 // TabContentsContainer, private: 54 // TabContentsContainer, private:
138 55
139 void TabContentsContainer::AddObservers() { 56 void TabContentsContainer::AddObservers() {
140 // TabContents can change their RenderViewHost and hence the HWND that is 57 // TabContents can change their RenderViewHost and hence the HWND that is
141 // shown and getting focused. We need to keep track of that so we install 58 // shown and getting focused. We need to keep track of that so we install
142 // the focus subclass on the shown HWND so we intercept focus change events. 59 // the focus subclass on the shown HWND so we intercept focus change events.
143 registrar_.Add(this, 60 registrar_.Add(this,
144 NotificationType::RENDER_VIEW_HOST_CHANGED, 61 NotificationType::RENDER_VIEW_HOST_CHANGED,
145 Source<NavigationController>(&tab_contents_->controller())); 62 Source<NavigationController>(&tab_contents_->controller()));
146 63
147 registrar_.Add(this, 64 registrar_.Add(this,
148 NotificationType::TAB_CONTENTS_DESTROYED, 65 NotificationType::TAB_CONTENTS_DESTROYED,
149 Source<TabContents>(tab_contents_)); 66 Source<TabContents>(tab_contents_));
150 } 67 }
151 68
152 void TabContentsContainer::RemoveObservers() { 69 void TabContentsContainer::RemoveObservers() {
153 registrar_.RemoveAll(); 70 registrar_.RemoveAll();
154 } 71 }
155 72
156 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host,
157 RenderViewHost* new_host) {
158 #if defined(TOUCH_UI)
159 NOTIMPLEMENTED(); // TODO(anicolao)
160 #else
161 if (new_host) {
162 RenderWidgetHostViewChanged(
163 old_host ? old_host->view() : NULL, new_host->view());
164 }
165 native_container_->RenderViewHostChanged(old_host, new_host);
166 #endif
167 }
168
169 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) { 73 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) {
170 // Sometimes, a TabContents is destroyed before we know about it. This allows 74 // Sometimes, a TabContents is destroyed before we know about it. This allows
171 // us to clean up our state in case this happens. 75 // us to clean up our state in case this happens.
172 DCHECK(contents == tab_contents_); 76 DCHECK(contents == tab_contents_);
173 ChangeTabContents(NULL); 77 ChangeTabContents(NULL);
174 } 78 }
175 79
176 void TabContentsContainer::RenderWidgetHostViewChanged( 80 void TabContentsContainer::RenderWidgetHostViewChanged(
177 RenderWidgetHostView* old_view, RenderWidgetHostView* new_view) { 81 RenderWidgetHostView* old_view, RenderWidgetHostView* new_view) {
178 // Carry over the reserved rect, if possible. 82 // Carry over the reserved rect, if possible.
179 if (old_view && new_view) { 83 if (old_view && new_view) {
180 new_view->set_reserved_contents_rect(old_view->reserved_contents_rect()); 84 new_view->set_reserved_contents_rect(old_view->reserved_contents_rect());
181 } else { 85 } else {
182 if (reserved_area_delegate_) 86 if (reserved_area_delegate_)
183 reserved_area_delegate_->UpdateReservedContentsRect(this); 87 reserved_area_delegate_->UpdateReservedContentsRect(this);
184 } 88 }
185 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698