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

Side by Side Diff: chrome/browser/ui/views/tab_contents/tab_contents_container_native.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: Merged with current head 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 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_CONTAINER_H_ 5 #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h"
6 #define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_CONTAINER_H_
7 #pragma once
8 6
7 #include "chrome/browser/renderer_host/render_view_host.h"
8 #include "chrome/browser/renderer_host/render_widget_host_view.h"
9 #include "chrome/browser/tab_contents/interstitial_page.h"
10 #include "chrome/browser/tab_contents/tab_contents.h"
11 #include "chrome/browser/ui/view_ids.h"
9 #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"
10 #include "chrome/common/notification_observer.h" 13 #include "chrome/common/notification_details.h"
11 #include "chrome/common/notification_registrar.h" 14 #include "chrome/common/notification_source.h"
12 #include "views/view.h"
13 15
14 class NativeTabContentsContainer; 16 // Some of this class is implemented in tab_contents_container.cc, where
15 class RenderViewHost; 17 // the implementation doesn't vary between a pure views approach and a
16 class RenderWidgetHostView; 18 // native view host approach. See the header file for details.
17 class TabContents;
18 19
19 class TabContentsContainer : public views::View, 20 ////////////////////////////////////////////////////////////////////////////////
20 public NotificationObserver { 21 // TabContentsContainer, public:
21 public:
22 TabContentsContainer();
23 virtual ~TabContentsContainer();
24 22
25 // Changes the TabContents associated with this view. 23 TabContentsContainer::TabContentsContainer()
26 void ChangeTabContents(TabContents* contents); 24 : native_container_(NULL),
25 tab_contents_(NULL) {
26 SetID(VIEW_ID_TAB_CONTAINER);
27 }
27 28
28 View* GetFocusView() { return native_container_->GetView(); } 29 void TabContentsContainer::ChangeTabContents(TabContents* contents) {
30 if (tab_contents_) {
31 native_container_->DetachContents(tab_contents_);
32 tab_contents_->WasHidden();
33 RemoveObservers();
34 }
35 tab_contents_ = contents;
36 // When detaching the last tab of the browser ChangeTabContents is invoked
37 // with NULL. Don't attempt to do anything in that case.
38 if (tab_contents_) {
39 RenderWidgetHostViewChanged(tab_contents_->GetRenderWidgetHostView());
40 native_container_->AttachContents(tab_contents_);
41 AddObservers();
42 }
43 }
29 44
30 // Accessor for |tab_contents_|. 45 void TabContentsContainer::TabContentsFocused(TabContents* tab_contents) {
31 TabContents* tab_contents() const { return tab_contents_; } 46 native_container_->TabContentsFocused(tab_contents);
47 }
32 48
33 // Called by the BrowserView to notify that |tab_contents| got the focus. 49 void TabContentsContainer::SetFastResize(bool fast_resize) {
34 void TabContentsFocused(TabContents* tab_contents); 50 native_container_->SetFastResize(fast_resize);
51 }
35 52
36 // Tells the container to update less frequently during resizing operations 53 ////////////////////////////////////////////////////////////////////////////////
37 // so performance is better. 54 // TabContentsContainer, View overrides:
38 void SetFastResize(bool fast_resize);
39 55
40 // Updates the current reserved rect in view coordinates where contents 56 void TabContentsContainer::Layout() {
41 // should not be rendered to draw the resize corner, sidebar mini tabs etc. 57 if (native_container_) {
42 void SetReservedContentsRect(const gfx::Rect& reserved_rect); 58 native_container_->GetView()->SetBounds(0, 0, width(), height());
59 native_container_->GetView()->Layout();
60 }
61 }
43 62
44 // Overridden from NotificationObserver: 63 void TabContentsContainer::ViewHierarchyChanged(bool is_add,
45 virtual void Observe(NotificationType type, 64 views::View* parent,
46 const NotificationSource& source, 65 views::View* child) {
47 const NotificationDetails& details); 66 if (is_add && child == this) {
67 native_container_ = NativeTabContentsContainer::CreateNativeContainer(this);
68 AddChildView(native_container_->GetView());
69 }
70 }
48 71
49 // Overridden from views::View: 72 ////////////////////////////////////////////////////////////////////////////////
50 virtual void Layout(); 73 // TabContentsContainer, private:
51 virtual AccessibilityTypes::Role GetAccessibleRole();
52 74
53 protected: 75 void TabContentsContainer::RenderViewHostChanged(RenderViewHost* old_host,
54 // Overridden from views::View: 76 RenderViewHost* new_host) {
55 virtual void ViewHierarchyChanged(bool is_add, views::View* parent, 77 if (new_host)
56 views::View* child); 78 RenderWidgetHostViewChanged(new_host->view());
57 79 native_container_->RenderViewHostChanged(old_host, new_host);
58 private: 80 }
59 // Add or remove observers for events that we care about.
60 void AddObservers();
61 void RemoveObservers();
62
63 // Called when the RenderViewHost of the hosted TabContents has changed, e.g.
64 // to show an interstitial page.
65 void RenderViewHostChanged(RenderViewHost* old_host,
66 RenderViewHost* new_host);
67
68 // Called when a TabContents is destroyed. This gives us a chance to clean
69 // up our internal state if the TabContents is somehow destroyed before we
70 // get notified.
71 void TabContentsDestroyed(TabContents* contents);
72
73 // Called when the RenderWidgetHostView of the hosted TabContents has changed.
74 void RenderWidgetHostViewChanged(RenderWidgetHostView* new_view);
75
76 // An instance of a NativeTabContentsContainer object that holds the native
77 // view handle associated with the attached TabContents.
78 NativeTabContentsContainer* native_container_;
79
80 // The attached TabContents.
81 TabContents* tab_contents_;
82
83 // Handles registering for our notifications.
84 NotificationRegistrar registrar_;
85
86 // The current reserved rect in view coordinates where contents should not be
87 // rendered to draw the resize corner, sidebar mini tabs etc.
88 // Cached here to update ever changing renderers.
89 gfx::Rect cached_reserved_rect_;
90
91 DISALLOW_COPY_AND_ASSIGN(TabContentsContainer);
92 };
93
94 #endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_TAB_CONTENTS_CONTAINER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698