Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 proxy_content_.reset(); | |
| 32 } | |
| 33 | |
| 34 void ContentProxy::ContentWillUnload() { | |
| 35 content_loaded_ = false; | |
| 36 } | |
| 37 | |
| 38 gfx::ImageSkia ContentProxy::GetContentImage() { | |
| 39 // For the time being we keep this here and return an empty image. | |
| 40 return image_; | |
| 41 } | |
| 42 | |
| 43 void ContentProxy::EvictContent() { | |
| 44 HideProxyContent(); | |
| 45 CreateSolidProxyContent(); | |
| 46 ShowProxyContent(); | |
| 47 } | |
| 48 | |
| 49 void ContentProxy::Reparent(aura::Window* new_parent_window) { | |
| 50 if (new_parent_window == window_) | |
| 51 return; | |
| 52 | |
| 53 // Since we are breaking now the connection to the old content, we make the | |
| 54 // content visible again before we continue. | |
| 55 // Note: Since the owning window is invisible, it does not matter that we | |
| 56 // make the web content visible if the window gets destroyed shortly after. | |
| 57 ShowOriginalContent(); | |
| 58 | |
| 59 // Transfer the |proxy_content_| to the passed window. | |
| 60 window_ = new_parent_window; | |
| 61 web_view_ = NULL; | |
| 62 | |
| 63 // Move the view to the new window and show it there. | |
| 64 HideOriginalContent(); | |
| 65 } | |
| 66 | |
| 67 void ContentProxy::ShowOriginalContent() { | |
| 68 // Hide our content. | |
| 69 HideProxyContent(); | |
| 70 | |
| 71 if (web_view_) { | |
| 72 // Show the original |web_view_| again. | |
| 73 web_view_->SetFastResize(false); | |
| 74 // If the content is loaded, we ask it to relayout itself since the | |
| 75 // dimensions might have changed. If not, we will reload new content and no | |
| 76 // layout is required for the old content. | |
| 77 if (content_loaded_) | |
| 78 web_view_->Layout(); | |
| 79 web_view_->GetWebContents()->GetNativeView()->Show(); | |
| 80 web_view_->SetVisible(true); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 void ContentProxy::HideOriginalContent() { | |
| 85 if (web_view_) { | |
| 86 // Hide the |web_view_|. | |
| 87 // TODO(skuhne): We might consider removing the view from the window while | |
| 88 // it's hidden - it should work the same way as show/hide and does not have | |
| 89 // any window re-ordering effect. | |
| 90 web_view_->GetWebContents()->GetNativeView()->Hide(); | |
| 91 web_view_->SetVisible(false); | |
| 92 // Don't allow the content to get resized with window size changes. | |
| 93 web_view_->SetFastResize(true); | |
| 94 } | |
| 95 | |
| 96 // Show our replacement content. | |
| 97 ShowProxyContent(); | |
| 98 } | |
| 99 | |
| 100 void ContentProxy::CreateProxyContent() { | |
| 101 // For the time being we create only a solid color here. | |
| 102 // TODO(skuhne): Replace with copying the drawn content into |proxy_content_| | |
| 103 // instead. | |
| 104 CreateSolidProxyContent(); | |
| 105 } | |
| 106 | |
| 107 void ContentProxy::CreateSolidProxyContent() { | |
| 108 proxy_content_.reset(new views::View()); | |
| 109 proxy_content_->set_background( | |
| 110 views::Background::CreateSolidBackground(background_color_)); | |
| 111 proxy_content_->SetFillsBoundsOpaquely(true); | |
|
pkotwicz
2014/09/10 14:30:21
Are there any cases where |proxy_content_| is pain
Mr4D (OOO till 08-26)
2014/09/10 15:55:45
Removed.
| |
| 112 } | |
| 113 | |
| 114 void ContentProxy::ShowProxyContent() { | |
| 115 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); | |
| 116 views::View* client_view = widget->client_view(); | |
| 117 // Place the view in front of all others. | |
| 118 client_view->AddChildViewAt(proxy_content_.get(), 0); | |
| 119 proxy_content_->SetSize(client_view->bounds().size()); | |
| 120 } | |
| 121 | |
| 122 void ContentProxy::HideProxyContent() { | |
| 123 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); | |
| 124 views::View* client_view = widget->client_view(); | |
| 125 client_view->RemoveChildView(proxy_content_.get()); | |
|
Jun Mukai
2014/09/10 00:38:53
views::View instance is owned by its parent. Ther
Mr4D (OOO till 08-26)
2014/09/10 15:55:45
Right - but the view does not get deleted by this
Jun Mukai
2014/09/10 21:04:57
Ah, I see, I was wrong (I believed RemoveChildView
| |
| 126 } | |
| 127 | |
| 128 } // namespace athena | |
| OLD | NEW |