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

Side by Side Diff: athena/content/app_activity.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: 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "athena/content/app_activity.h" 5 #include "athena/content/app_activity.h"
6 6
7 #include "athena/activity/public/activity_manager.h" 7 #include "athena/activity/public/activity_manager.h"
8 #include "athena/content/app_activity_registry.h" 8 #include "athena/content/app_activity_registry.h"
9 #include "athena/content/content_proxy.h"
9 #include "athena/content/public/app_registry.h" 10 #include "athena/content/public/app_registry.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
11 #include "ui/aura/window.h" 12 #include "ui/aura/window.h"
12 #include "ui/views/controls/webview/webview.h" 13 #include "ui/views/controls/webview/webview.h"
13 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
14 15
15 namespace athena { 16 namespace athena {
16 17
17 // TODO(mukai): specifies the same accelerators of WebActivity. 18 // TODO(mukai): specifies the same accelerators of WebActivity.
18 AppActivity::AppActivity(const std::string& app_id) 19 AppActivity::AppActivity(const std::string& app_id)
19 : app_id_(app_id), 20 : app_id_(app_id),
20 web_view_(NULL), 21 web_view_(NULL),
21 current_state_(ACTIVITY_UNLOADED), 22 current_state_(ACTIVITY_UNLOADED),
22 app_activity_registry_(NULL) { 23 app_activity_registry_(NULL) {
23 } 24 }
24 25
26 scoped_ptr<ContentProxy> AppActivity::GetContentProxy(aura::Window* window) {
27 if (content_proxy_.get())
28 content_proxy_->Reparent(window);
29 return content_proxy_.Pass();
30 }
31
25 ActivityViewModel* AppActivity::GetActivityViewModel() { 32 ActivityViewModel* AppActivity::GetActivityViewModel() {
26 return this; 33 return this;
27 } 34 }
28 35
29 void AppActivity::SetCurrentState(Activity::ActivityState state) { 36 void AppActivity::SetCurrentState(Activity::ActivityState state) {
30 DCHECK_NE(state, current_state_); 37 DCHECK_NE(state, current_state_);
31 ActivityState current_state = current_state_; 38 ActivityState current_state = current_state_;
32 // Remember the last requested state now so that a call to GetCurrentState() 39 // Remember the last requested state now so that a call to GetCurrentState()
33 // returns the new state. 40 // returns the new state.
34 current_state_ = state; 41 current_state_ = state;
35 42
36 switch (state) { 43 switch (state) {
37 case ACTIVITY_VISIBLE: 44 case ACTIVITY_VISIBLE:
38 MakeVisible(); 45 HideContentProxy();
39 return; 46 return;
40 case ACTIVITY_INVISIBLE: 47 case ACTIVITY_INVISIBLE:
41 if (current_state == ACTIVITY_VISIBLE) 48 if (current_state == ACTIVITY_VISIBLE)
42 MakeInvisible(); 49 ShowContentProxy();
43 break; 50 break;
44 case ACTIVITY_BACKGROUND_LOW_PRIORITY: 51 case ACTIVITY_BACKGROUND_LOW_PRIORITY:
45 DCHECK(ACTIVITY_VISIBLE == current_state || 52 DCHECK(ACTIVITY_VISIBLE == current_state ||
46 ACTIVITY_INVISIBLE == current_state); 53 ACTIVITY_INVISIBLE == current_state);
47 // TODO(skuhne): Do this. 54 // TODO(skuhne): Do this.
48 break; 55 break;
49 case ACTIVITY_PERSISTENT: 56 case ACTIVITY_PERSISTENT:
50 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state); 57 DCHECK_EQ(ACTIVITY_BACKGROUND_LOW_PRIORITY, current_state);
51 // TODO(skuhne): Do this. 58 // TODO(skuhne): Do this.
52 break; 59 break;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 119 }
113 120
114 views::View* AppActivity::GetContentsView() { 121 views::View* AppActivity::GetContentsView() {
115 if (!web_view_) { 122 if (!web_view_) {
116 // TODO(oshima): use apps::NativeAppWindowViews 123 // TODO(oshima): use apps::NativeAppWindowViews
117 content::WebContents* web_contents = GetWebContents(); 124 content::WebContents* web_contents = GetWebContents();
118 web_view_ = new views::WebView(web_contents->GetBrowserContext()); 125 web_view_ = new views::WebView(web_contents->GetBrowserContext());
119 web_view_->SetWebContents(web_contents); 126 web_view_->SetWebContents(web_contents);
120 // Make sure the content gets properly shown. 127 // Make sure the content gets properly shown.
121 if (current_state_ == ACTIVITY_VISIBLE) { 128 if (current_state_ == ACTIVITY_VISIBLE) {
122 MakeVisible(); 129 HideContentProxy();
123 } else if (current_state_ == ACTIVITY_INVISIBLE) { 130 } else if (current_state_ == ACTIVITY_INVISIBLE) {
124 MakeInvisible(); 131 ShowContentProxy();
125 } else { 132 } else {
126 // If not previously specified, we change the state now to invisible.. 133 // If not previously specified, we change the state now to invisible..
127 SetCurrentState(ACTIVITY_INVISIBLE); 134 SetCurrentState(ACTIVITY_INVISIBLE);
128 } 135 }
129 Observe(web_contents); 136 Observe(web_contents);
130 RegisterActivity(); 137 RegisterActivity();
131 } 138 }
132 return web_view_; 139 return web_view_;
133 } 140 }
134 141
135 void AppActivity::CreateOverviewModeImage() {
136 // TODO(skuhne): Implement this!
137 }
138
139 gfx::ImageSkia AppActivity::GetOverviewModeImage() { 142 gfx::ImageSkia AppActivity::GetOverviewModeImage() {
140 return overview_mode_image_; 143 if (content_proxy_.get())
144 return content_proxy_->GetContentImage();
145 return gfx::ImageSkia();
141 } 146 }
142 147
143 void AppActivity::PrepareContentsForOverview() { 148 void AppActivity::PrepareContentsForOverview() {
144 // Turn on fast resizing to avoid re-laying out the web contents when 149 // Turn on fast resizing to avoid re-laying out the web contents when
145 // entering / exiting overview mode. 150 // entering / exiting overview mode and the content is visible.
146 web_view_->SetFastResize(true); 151 if (!content_proxy_.get())
152 web_view_->SetFastResize(true);
147 } 153 }
148 154
149 void AppActivity::ResetContentsView() { 155 void AppActivity::ResetContentsView() {
150 web_view_->SetFastResize(false); 156 // Turn on fast resizing to avoid re-laying out the web contents when
151 web_view_->Layout(); 157 // entering / exiting overview mode and the content is visible.
158 if (!content_proxy_.get()) {
159 web_view_->SetFastResize(false);
160 web_view_->Layout();
161 }
152 } 162 }
153 163
154 AppActivity::~AppActivity() { 164 AppActivity::~AppActivity() {
155 // If this activity is registered, we unregister it now. 165 // If this activity is registered, we unregister it now.
156 if (app_activity_registry_) 166 if (app_activity_registry_)
157 app_activity_registry_->UnregisterAppActivity(this); 167 app_activity_registry_->UnregisterAppActivity(this);
158 } 168 }
159 169
160 void AppActivity::TitleWasSet(content::NavigationEntry* entry, 170 void AppActivity::TitleWasSet(content::NavigationEntry* entry,
161 bool explicit_set) { 171 bool explicit_set) {
(...skipping 12 matching lines...) Expand all
174 content::WebContents* web_contents = GetWebContents(); 184 content::WebContents* web_contents = GetWebContents();
175 AppRegistry* app_registry = AppRegistry::Get(); 185 AppRegistry* app_registry = AppRegistry::Get();
176 // Get the application's registry. 186 // Get the application's registry.
177 app_activity_registry_ = app_registry->GetAppActivityRegistry( 187 app_activity_registry_ = app_registry->GetAppActivityRegistry(
178 app_id_, web_contents->GetBrowserContext()); 188 app_id_, web_contents->GetBrowserContext());
179 DCHECK(app_activity_registry_); 189 DCHECK(app_activity_registry_);
180 // Register the activity. 190 // Register the activity.
181 app_activity_registry_->RegisterAppActivity(this); 191 app_activity_registry_->RegisterAppActivity(this);
182 } 192 }
183 193
184 void AppActivity::MakeVisible() { 194 void AppActivity::HideContentProxy() {
185 // TODO(skuhne): Once we know how to handle the Overview mode, this has to 195 if (content_proxy_.get())
186 // be moved into an ActivityContentController which is used by all activities. 196 content_proxy_.reset(NULL);
Jun Mukai 2014/09/10 00:38:53 you can omit NULL, i.e. reset(); Also, you can re
Mr4D (OOO till 08-26) 2014/09/10 15:55:45 Done.
187 // Make the content visible.
188 // TODO(skuhne): If this can be combined with web_activity, move this into a
189 // separate class.
190 web_view_->SetVisible(true);
191 web_view_->GetWebContents()->GetNativeView()->Show();
192
193 // Remove our proxy image.
194 // TODO(skuhne): Once we have figured out how to do overview mode that code
195 // needs to go here.
196 overview_mode_image_ = gfx::ImageSkia();
197 } 197 }
198 198
199 void AppActivity::MakeInvisible() { 199 void AppActivity::ShowContentProxy() {
200 // TODO(skuhne): Once we know how to handle the Overview mode, this has to 200 if (!content_proxy_.get() && web_view_)
201 // be moved into an ActivityContentController which is used by all activities. 201 content_proxy_.reset(new ContentProxy(web_view_, this));
202 // TODO(skuhne): If this can be combined with web_activity, move this into a
203 // separate class.
204 DCHECK(web_view_->visible());
205 // Create our proxy image.
206 if (current_state_ == ACTIVITY_VISIBLE) {
207 // Create a proxy image of the current visible content.
208 // TODO(skuhne): Do this once we figure out how to do overview mode.
209 overview_mode_image_ = gfx::ImageSkia();
210 }
211 // Now we can hide this.
212 // Note: This might have to be done asynchronously after the readback took
213 // place.
214 web_view_->SetVisible(false);
215 web_view_->GetWebContents()->GetNativeView()->Hide();
216 } 202 }
217 203
218 } // namespace athena 204 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698