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

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

Issue 5606012: Streamline the layout of the BrowserView's children TabContents views.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years 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 // 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/renderer_host/render_view_host.h" 7 #include "chrome/browser/renderer_host/render_view_host.h"
8 #include "chrome/browser/renderer_host/render_widget_host_view.h" 8 #include "chrome/browser/renderer_host/render_widget_host_view.h"
9 #include "chrome/browser/tab_contents/interstitial_page.h" 9 #include "chrome/browser/tab_contents/interstitial_page.h"
10 #include "chrome/browser/tab_contents/tab_contents.h" 10 #include "chrome/browser/tab_contents/tab_contents.h"
11 #include "chrome/browser/ui/view_ids.h" 11 #include "chrome/browser/ui/view_ids.h"
12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" 12 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h"
13 #include "chrome/common/notification_service.h" 13 #include "chrome/common/notification_service.h"
14 14
15 #if defined(TOUCH_UI) 15 #if defined(TOUCH_UI)
16 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk .h" 16 #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk .h"
17 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" 17 #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h"
18 #include "views/border.h" 18 #include "views/border.h"
19 #include "views/fill_layout.h" 19 #include "views/fill_layout.h"
20 #endif 20 #endif
21 21
22 //////////////////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////////////////
23 // TabContentsContainer, public: 23 // TabContentsContainer, public:
24 24
25 TabContentsContainer::TabContentsContainer() 25 TabContentsContainer::TabContentsContainer()
26 : native_container_(NULL), 26 : native_container_(NULL),
27 tab_contents_(NULL), 27 tab_contents_(NULL) {
28 reserved_area_delegate_(NULL) {
29 SetID(VIEW_ID_TAB_CONTAINER); 28 SetID(VIEW_ID_TAB_CONTAINER);
30 } 29 }
31 30
32 TabContentsContainer::~TabContentsContainer() { 31 TabContentsContainer::~TabContentsContainer() {
33 if (tab_contents_) 32 if (tab_contents_)
34 RemoveObservers(); 33 RemoveObservers();
35 } 34 }
36 35
37 void TabContentsContainer::ChangeTabContents(TabContents* contents) { 36 void TabContentsContainer::ChangeTabContents(TabContents* contents) {
38 if (tab_contents_) { 37 if (tab_contents_) {
39 #if !defined(TOUCH_UI) 38 #if !defined(TOUCH_UI)
40 native_container_->DetachContents(tab_contents_); 39 native_container_->DetachContents(tab_contents_);
41 #endif 40 #endif
42 tab_contents_->WasHidden(); 41 tab_contents_->WasHidden();
43 RemoveObservers(); 42 RemoveObservers();
44 } 43 }
45 #if !defined(TOUCH_UI)
46 TabContents* old_contents = tab_contents_;
47 #endif
48 tab_contents_ = contents; 44 tab_contents_ = contents;
49 // When detaching the last tab of the browser ChangeTabContents is invoked 45 // When detaching the last tab of the browser ChangeTabContents is invoked
50 // with NULL. Don't attempt to do anything in that case. 46 // with NULL. Don't attempt to do anything in that case.
51 if (tab_contents_) { 47 if (tab_contents_) {
52 #if defined(TOUCH_UI) 48 #if defined(TOUCH_UI)
53 views::View *v = static_cast<TabContentsViewViews*>(contents->view()); 49 views::View *v = static_cast<TabContentsViewViews*>(contents->view());
54 // Guard against re-adding ourselves, which happens because the NULL 50 // Guard against re-adding ourselves, which happens because the NULL
55 // value is ignored by the pre-existing if() above. 51 // value is ignored by the pre-existing if() above.
56 if (v->GetParent() != this) { 52 if (v->GetParent() != this) {
57 AddChildView(v); 53 AddChildView(v);
58 SetLayoutManager(new views::FillLayout()); 54 SetLayoutManager(new views::FillLayout());
59 Layout(); 55 Layout();
60 } 56 }
61 #else 57 #else
62 RenderWidgetHostViewChanged( 58 RenderWidgetHostViewChanged(tab_contents_->GetRenderWidgetHostView());
63 old_contents ? old_contents->GetRenderWidgetHostView() : NULL,
64 tab_contents_->GetRenderWidgetHostView());
65 native_container_->AttachContents(tab_contents_); 59 native_container_->AttachContents(tab_contents_);
66 #endif 60 #endif
67 AddObservers(); 61 AddObservers();
68 } 62 }
69 } 63 }
70 64
71 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) { 65 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) {
72 if (native_container_) 66 if (native_container_)
73 native_container_->TabContentsFocused(tab_contents); 67 native_container_->TabContentsFocused(tab_contents);
74 } 68 }
75 69
76 void TabContentsContainer::SetFastResize(bool fast_resize) { 70 void TabContentsContainer::SetFastResize(bool fast_resize) {
77 if (native_container_) 71 if (native_container_)
78 native_container_->SetFastResize(fast_resize); 72 native_container_->SetFastResize(fast_resize);
79 } 73 }
80 74
75 void TabContentsContainer::SetReservedContentsRect(
76 const gfx::Rect& reserved_rect) {
77 cached_reserved_rect_ = reserved_rect;
78 #if !defined(TOUCH_UI)
79 if (tab_contents_ && tab_contents_->GetRenderWidgetHostView()) {
80 tab_contents_->GetRenderWidgetHostView()->set_reserved_contents_rect(
81 reserved_rect);
82 }
83 #endif
84 }
85
81 //////////////////////////////////////////////////////////////////////////////// 86 ////////////////////////////////////////////////////////////////////////////////
82 // TabContentsContainer, NotificationObserver implementation: 87 // TabContentsContainer, NotificationObserver implementation:
83 88
84 void TabContentsContainer::Observe(NotificationType type, 89 void TabContentsContainer::Observe(NotificationType type,
85 const NotificationSource& source, 90 const NotificationSource& source,
86 const NotificationDetails& details) { 91 const NotificationDetails& details) {
87 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { 92 if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) {
88 RenderViewHostSwitchedDetails* switched_details = 93 RenderViewHostSwitchedDetails* switched_details =
89 Details<RenderViewHostSwitchedDetails>(details).ptr(); 94 Details<RenderViewHostSwitchedDetails>(details).ptr();
90 RenderViewHostChanged(switched_details->old_host, 95 RenderViewHostChanged(switched_details->old_host,
91 switched_details->new_host); 96 switched_details->new_host);
92 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { 97 } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) {
93 TabContentsDestroyed(Source<TabContents>(source).ptr()); 98 TabContentsDestroyed(Source<TabContents>(source).ptr());
94 } else { 99 } else {
95 NOTREACHED(); 100 NOTREACHED();
96 } 101 }
97 } 102 }
98 103
99 //////////////////////////////////////////////////////////////////////////////// 104 ////////////////////////////////////////////////////////////////////////////////
100 // TabContentsContainer, View overrides: 105 // TabContentsContainer, View overrides:
101 106
102 void TabContentsContainer::Layout() { 107 void TabContentsContainer::Layout() {
103 #if defined(TOUCH_UI) 108 #if defined(TOUCH_UI)
104 views::View::Layout(); 109 views::View::Layout();
105 #else 110 #else
106 if (native_container_) { 111 if (native_container_) {
107 if (reserved_area_delegate_)
108 reserved_area_delegate_->UpdateReservedContentsRect(this);
109 native_container_->GetView()->SetBounds(0, 0, width(), height()); 112 native_container_->GetView()->SetBounds(0, 0, width(), height());
110 native_container_->GetView()->Layout(); 113 native_container_->GetView()->Layout();
111 } 114 }
112 #endif 115 #endif
113 } 116 }
114 117
115 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() { 118 AccessibilityTypes::Role TabContentsContainer::GetAccessibleRole() {
116 return AccessibilityTypes::ROLE_WINDOW; 119 return AccessibilityTypes::ROLE_WINDOW;
117 } 120 }
118 121
(...skipping 26 matching lines...) Expand all
145 Source<TabContents>(tab_contents_)); 148 Source<TabContents>(tab_contents_));
146 } 149 }
147 150
148 void TabContentsContainer::RemoveObservers() { 151 void TabContentsContainer::RemoveObservers() {
149 registrar_.RemoveAll(); 152 registrar_.RemoveAll();
150 } 153 }
151 154
152 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host, 155 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host,
153 RenderViewHost* new_host) { 156 RenderViewHost* new_host) {
154 #if defined(TOUCH_UI) 157 #if defined(TOUCH_UI)
155 NOTIMPLEMENTED(); // TODO(anicolao) 158 NOTIMPLEMENTED(); // TODO(anicolao)
156 #else 159 #else
157 if (new_host) { 160 if (new_host)
158 RenderWidgetHostViewChanged( 161 RenderWidgetHostViewChanged(new_host->view());
159 old_host ? old_host->view() : NULL, new_host->view());
160 }
161 native_container_->RenderViewHostChanged(old_host, new_host); 162 native_container_->RenderViewHostChanged(old_host, new_host);
162 #endif 163 #endif
163 } 164 }
164 165
165 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) { 166 void TabContentsContainer::TabContentsDestroyed(TabContents* contents) {
166 // Sometimes, a TabContents is destroyed before we know about it. This allows 167 // Sometimes, a TabContents is destroyed before we know about it. This allows
167 // us to clean up our state in case this happens. 168 // us to clean up our state in case this happens.
168 DCHECK(contents == tab_contents_); 169 DCHECK(contents == tab_contents_);
169 ChangeTabContents(NULL); 170 ChangeTabContents(NULL);
170 } 171 }
171 172
172 void TabContentsContainer::RenderWidgetHostViewChanged( 173 void TabContentsContainer::RenderWidgetHostViewChanged(
173 RenderWidgetHostView* old_view, RenderWidgetHostView* new_view) { 174 RenderWidgetHostView* new_view) {
174 // Carry over the reserved rect, if possible. 175 if (new_view)
175 if (old_view && new_view) { 176 new_view->set_reserved_contents_rect(cached_reserved_rect_);
176 new_view->set_reserved_contents_rect(old_view->reserved_contents_rect());
177 } else {
178 if (reserved_area_delegate_)
179 reserved_area_delegate_->UpdateReservedContentsRect(this);
180 }
181 } 177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698