OLD | NEW |
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/web_activity.h" | 5 #include "athena/content/web_activity.h" |
6 | 6 |
7 #include "athena/activity/public/activity_factory.h" | 7 #include "athena/activity/public/activity_factory.h" |
8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
9 #include "athena/input/public/accelerator_manager.h" | 9 #include "athena/input/public/accelerator_manager.h" |
| 10 #include "base/bind.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "content/public/browser/native_web_keyboard_event.h" | 12 #include "content/public/browser/native_web_keyboard_event.h" |
12 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
14 #include "content/public/browser/web_contents_delegate.h" | 15 #include "content/public/browser/web_contents_delegate.h" |
15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/compositor/closure_animation_observer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
16 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 19 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
17 #include "ui/views/controls/webview/webview.h" | 20 #include "ui/views/controls/webview/webview.h" |
18 #include "ui/views/focus/focus_manager.h" | 21 #include "ui/views/focus/focus_manager.h" |
19 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
20 | 23 |
21 namespace athena { | 24 namespace athena { |
22 namespace { | 25 namespace { |
23 | 26 |
24 class WebActivityController : public AcceleratorHandler { | 27 class WebActivityController : public AcceleratorHandler { |
25 public: | 28 public: |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 bool enter_fullscreen) OVERRIDE { | 252 bool enter_fullscreen) OVERRIDE { |
250 fullscreen_ = enter_fullscreen; | 253 fullscreen_ = enter_fullscreen; |
251 GetWidget()->SetFullscreen(fullscreen_); | 254 GetWidget()->SetFullscreen(fullscreen_); |
252 } | 255 } |
253 | 256 |
254 virtual bool IsFullscreenForTabOrPending( | 257 virtual bool IsFullscreenForTabOrPending( |
255 const content::WebContents* web_contents) const OVERRIDE { | 258 const content::WebContents* web_contents) const OVERRIDE { |
256 return fullscreen_; | 259 return fullscreen_; |
257 } | 260 } |
258 | 261 |
| 262 virtual void LoadingStateChanged(content::WebContents* source, |
| 263 bool to_different_document) OVERRIDE { |
| 264 bool has_stopped = source == NULL || !source->IsLoading(); |
| 265 LoadProgressChanged(source, has_stopped ? 1 : 0); |
| 266 } |
| 267 |
| 268 virtual void LoadProgressChanged(content::WebContents* source, |
| 269 double progress) OVERRIDE { |
| 270 if (!progress) |
| 271 return; |
| 272 |
| 273 if (!progress_bar_) { |
| 274 CreateProgressBar(); |
| 275 source->GetNativeView()->layer()->Add(progress_bar_.get()); |
| 276 } |
| 277 progress_bar_->SetBounds(gfx::Rect( |
| 278 0, 0, progress * progress_bar_->parent()->bounds().width(), 3)); |
| 279 if (progress < 1) |
| 280 return; |
| 281 |
| 282 ui::ScopedLayerAnimationSettings settings(progress_bar_->GetAnimator()); |
| 283 settings.SetTweenType(gfx::Tween::EASE_IN); |
| 284 ui::Layer* layer = progress_bar_.get(); |
| 285 settings.AddObserver(new ui::ClosureAnimationObserver( |
| 286 base::Bind(&base::DeletePointer<ui::Layer>, progress_bar_.release()))); |
| 287 layer->SetOpacity(0.f); |
| 288 } |
| 289 |
259 private: | 290 private: |
| 291 void CreateProgressBar() { |
| 292 CHECK(!progress_bar_); |
| 293 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 294 progress_bar_->SetColor(SkColorSetRGB(0x00, 0xb0, 0xc7)); |
| 295 } |
| 296 |
260 scoped_ptr<WebActivityController> controller_; | 297 scoped_ptr<WebActivityController> controller_; |
261 | 298 |
262 // If the activity got evicted, this is the web content which holds the known | 299 // If the activity got evicted, this is the web content which holds the known |
263 // state of the content before eviction. | 300 // state of the content before eviction. |
264 scoped_ptr<content::WebContents> evicted_web_contents_; | 301 scoped_ptr<content::WebContents> evicted_web_contents_; |
265 | 302 |
| 303 scoped_ptr<ui::Layer> progress_bar_; |
| 304 |
266 // TODO(oshima): Find out if we should support window fullscreen. | 305 // TODO(oshima): Find out if we should support window fullscreen. |
267 // It may still useful when a user is in split mode. | 306 // It may still useful when a user is in split mode. |
268 bool fullscreen_; | 307 bool fullscreen_; |
269 | 308 |
270 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); | 309 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); |
271 }; | 310 }; |
272 | 311 |
273 WebActivity::WebActivity(content::BrowserContext* browser_context, | 312 WebActivity::WebActivity(content::BrowserContext* browser_context, |
274 const GURL& url) | 313 const GURL& url) |
275 : browser_context_(browser_context), | 314 : browser_context_(browser_context), |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 void WebActivity::DidUpdateFaviconURL( | 451 void WebActivity::DidUpdateFaviconURL( |
413 const std::vector<content::FaviconURL>& candidates) { | 452 const std::vector<content::FaviconURL>& candidates) { |
414 ActivityManager::Get()->UpdateActivity(this); | 453 ActivityManager::Get()->UpdateActivity(this); |
415 } | 454 } |
416 | 455 |
417 void WebActivity::DidChangeThemeColor(SkColor theme_color) { | 456 void WebActivity::DidChangeThemeColor(SkColor theme_color) { |
418 title_color_ = theme_color; | 457 title_color_ = theme_color; |
419 } | 458 } |
420 | 459 |
421 } // namespace athena | 460 } // namespace athena |
OLD | NEW |