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

Side by Side Diff: athena/content/content_proxy.cc

Issue 548633005: Adding overview / layer framework to Activities so that unloaded / sleeping activities can be shown… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, fixed resulting problems and addressed comments Created 6 years, 3 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "athena/content/content_proxy.h"
6
7 #include "athena/activity/public/activity.h"
8 #include "athena/activity/public/activity_view_model.h"
9 #include "content/public/browser/web_contents.h"
10 #include "ui/aura/window.h"
11 #include "ui/views/background.h"
12 #include "ui/views/controls/webview/webview.h"
13 #include "ui/views/widget/widget.h"
14
15 namespace athena {
16
17 ContentProxy::ContentProxy(views::WebView* web_view, Activity* activity)
18 : web_view_(web_view),
19 window_(activity->GetWindow()),
20 background_color_(
21 activity->GetActivityViewModel()->GetRepresentativeColor()),
22 content_loaded_(true) {
23 CreateProxyContent();
24 HideOriginalContent();
25 }
26
27 ContentProxy::~ContentProxy() {
28 // If we still have a connection to the original Activity, we make it visible
29 // again.
30 ShowOriginalContent();
31 // At this point we should either have no view - or the view should not be
32 // shown by its parent anymore.
33 DCHECK(!proxy_content_.get() || !proxy_content_->parent());
34 proxy_content_.reset();
35 }
36
37 void ContentProxy::ContentWillUnload() {
38 content_loaded_ = false;
39 }
40
41 gfx::ImageSkia ContentProxy::GetContentImage() {
42 // For the time being we keep this here and return an empty image.
43 return image_;
44 }
45
46 void ContentProxy::EvictContent() {
47 HideProxyContent();
48 CreateSolidProxyContent();
49 ShowProxyContent();
50 }
51
52 void ContentProxy::Reparent(aura::Window* new_parent_window) {
53 if (new_parent_window == window_)
54 return;
55
56 // Since we are breaking now the connection to the old content, we make the
57 // content visible again before we continue.
58 // Note: Since the owning window is invisible, it does not matter that we
59 // make the web content visible if the window gets destroyed shortly after.
60 ShowOriginalContent();
61
62 // Transfer the |proxy_content_| to the passed window.
63 window_ = new_parent_window;
64 web_view_ = NULL;
65
66 // Move the view to the new window and show it there.
67 HideOriginalContent();
68 }
69
70 void ContentProxy::ShowOriginalContent() {
71 // Hide our content.
72 HideProxyContent();
73
74 if (web_view_) {
75 // Show the original |web_view_| again.
76 web_view_->SetFastResize(false);
77 // If the content is loaded, we ask it to relayout itself since the
78 // dimensions might have changed. If not, we will reload new content and no
79 // layout is required for the old content.
80 if (content_loaded_)
81 web_view_->Layout();
82 web_view_->GetWebContents()->GetNativeView()->Show();
83 web_view_->SetVisible(true);
84 }
85 }
86
87 void ContentProxy::HideOriginalContent() {
88 if (web_view_) {
89 // Hide the |web_view_|.
90 // TODO(skuhne): We might consider removing the view from the window while
91 // it's hidden - it should work the same way as show/hide and does not have
92 // any window re-ordering effect.
93 web_view_->GetWebContents()->GetNativeView()->Hide();
94 web_view_->SetVisible(false);
95 // Don't allow the content to get resized with window size changes.
96 web_view_->SetFastResize(true);
97 }
98
99 // Show our replacement content.
100 ShowProxyContent();
101 }
102
103 void ContentProxy::CreateProxyContent() {
104 // For the time being we create only a solid color here.
105 // TODO(skuhne): Replace with copying the drawn content into |proxy_content_|
106 // instead.
107 CreateSolidProxyContent();
108 }
109
110 void ContentProxy::CreateSolidProxyContent() {
111 proxy_content_.reset(new views::View());
112 proxy_content_->set_owned_by_client();
113 proxy_content_->set_background(
114 views::Background::CreateSolidBackground(background_color_));
115 }
116
117 void ContentProxy::ShowProxyContent() {
118 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_);
119 DCHECK(widget);
120 views::View* client_view = widget->client_view();
121 // Place the view in front of all others.
122 client_view->AddChildViewAt(proxy_content_.get(),
123 client_view->child_count() - 1);
sadrul 2014/09/12 16:30:14 This is going to add the view just behind the fron
Mr4D (OOO till 08-26) 2014/09/12 20:11:26 Done.
124 proxy_content_->SetSize(client_view->bounds().size());
125 }
126
127 void ContentProxy::HideProxyContent() {
128 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_);
129 views::View* client_view = widget->client_view();
130 client_view->RemoveChildView(proxy_content_.get());
131 }
132
133 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698