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/content/public/dialogs.h" | 9 #include "athena/content/public/dialogs.h" |
10 #include "athena/input/public/accelerator_manager.h" | 10 #include "athena/input/public/accelerator_manager.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "components/favicon_base/select_favicon_frames.h" | 14 #include "components/favicon_base/select_favicon_frames.h" |
15 #include "content/public/browser/native_web_keyboard_event.h" | 15 #include "content/public/browser/native_web_keyboard_event.h" |
16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/browser/web_contents_delegate.h" | 18 #include "content/public/browser/web_contents_delegate.h" |
19 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
20 #include "content/public/common/favicon_url.h" | 20 #include "content/public/common/favicon_url.h" |
21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/compositor/closure_animation_observer.h" | 22 #include "ui/compositor/closure_animation_observer.h" |
23 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
24 #include "ui/views/background.h" | |
25 #include "ui/views/controls/label.h" | |
24 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" | 26 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" |
25 #include "ui/views/controls/webview/webview.h" | 27 #include "ui/views/controls/webview/webview.h" |
26 #include "ui/views/focus/focus_manager.h" | 28 #include "ui/views/focus/focus_manager.h" |
27 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
28 | 30 |
29 namespace athena { | 31 namespace athena { |
30 namespace { | 32 namespace { |
31 | 33 |
32 class WebActivityController : public AcceleratorHandler { | 34 class WebActivityController : public AcceleratorHandler { |
33 public: | 35 public: |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 bool reserved_accelerator_enabled_; | 144 bool reserved_accelerator_enabled_; |
143 scoped_ptr<AcceleratorManager> accelerator_manager_; | 145 scoped_ptr<AcceleratorManager> accelerator_manager_; |
144 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; | 146 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; |
145 | 147 |
146 DISALLOW_COPY_AND_ASSIGN(WebActivityController); | 148 DISALLOW_COPY_AND_ASSIGN(WebActivityController); |
147 }; | 149 }; |
148 | 150 |
149 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2); | 151 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2); |
150 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77); | 152 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77); |
151 const int kIconSize = 32; | 153 const int kIconSize = 32; |
154 const int kDistanceShowReloadMessage = 30; | |
155 const int kDistanceReload = 70; | |
152 | 156 |
153 } // namespace | 157 } // namespace |
154 | 158 |
155 // A web view for athena's web activity. Note that AthenaWebView will create its | 159 // A web view for athena's web activity. Note that AthenaWebView will create its |
156 // own content so that it can eject and reload it. | 160 // own content so that it can eject and reload it. |
157 class AthenaWebView : public views::WebView { | 161 class AthenaWebView : public views::WebView { |
158 public: | 162 public: |
159 AthenaWebView(content::BrowserContext* context) | 163 AthenaWebView(content::BrowserContext* context) |
160 : views::WebView(context), controller_(new WebActivityController(this)), | 164 : views::WebView(context), controller_(new WebActivityController(this)), |
161 fullscreen_(false) { | 165 fullscreen_(false), |
166 overscroll_y_(0) { | |
162 SetEmbedFullscreenWidgetMode(true); | 167 SetEmbedFullscreenWidgetMode(true); |
163 // TODO(skuhne): Add content observer to detect renderer crash and set | 168 // TODO(skuhne): Add content observer to detect renderer crash and set |
164 // content status to unloaded if that happens. | 169 // content status to unloaded if that happens. |
165 } | 170 } |
166 | 171 |
167 AthenaWebView(content::WebContents* web_contents) | 172 AthenaWebView(content::WebContents* web_contents) |
168 : views::WebView(web_contents->GetBrowserContext()), | 173 : views::WebView(web_contents->GetBrowserContext()), |
169 controller_(new WebActivityController(this)) { | 174 controller_(new WebActivityController(this)) { |
170 scoped_ptr<content::WebContents> old_contents( | 175 scoped_ptr<content::WebContents> old_contents( |
171 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); | 176 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 // NULL is returned if the URL wasn't opened immediately. | 241 // NULL is returned if the URL wasn't opened immediately. |
237 return NULL; | 242 return NULL; |
238 } | 243 } |
239 | 244 |
240 virtual bool CanOverscrollContent() const OVERRIDE { | 245 virtual bool CanOverscrollContent() const OVERRIDE { |
241 const std::string value = CommandLine::ForCurrentProcess()-> | 246 const std::string value = CommandLine::ForCurrentProcess()-> |
242 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); | 247 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); |
243 return value != "0"; | 248 return value != "0"; |
244 } | 249 } |
245 | 250 |
251 virtual void OverscrollUpdate(int delta_y) OVERRIDE { | |
252 overscroll_y_ = delta_y; | |
253 if (overscroll_y_ > kDistanceShowReloadMessage) { | |
254 if (!reload_message_) | |
255 CreateReloadMessage(); | |
256 reload_message_->Show(); | |
257 float opacity = 1.0f; | |
258 if (overscroll_y_ < kDistanceReload) { | |
259 opacity = | |
260 (overscroll_y_ - kDistanceShowReloadMessage) / | |
261 static_cast<float>(kDistanceReload - kDistanceShowReloadMessage); | |
262 } | |
263 reload_message_->GetLayer()->SetOpacity(opacity); | |
264 } else if (reload_message_) { | |
265 reload_message_->Hide(); | |
266 } | |
267 } | |
268 | |
269 virtual void OverscrollComplete() OVERRIDE { | |
270 if (overscroll_y_ >= kDistanceReload) { | |
271 reload_message_->Hide(); | |
mfomitchev
2014/09/17 21:57:22
Shouldn't we hide the widget and reset overscroll_
pkotwicz
2014/09/18 14:18:32
Thanks for pointing this out. Fixed!
| |
272 overscroll_y_ = 0; | |
273 | |
274 GetWebContents()->GetController().Reload(false); | |
275 } | |
276 } | |
277 | |
246 virtual void AddNewContents(content::WebContents* source, | 278 virtual void AddNewContents(content::WebContents* source, |
247 content::WebContents* new_contents, | 279 content::WebContents* new_contents, |
248 WindowOpenDisposition disposition, | 280 WindowOpenDisposition disposition, |
249 const gfx::Rect& initial_pos, | 281 const gfx::Rect& initial_pos, |
250 bool user_gesture, | 282 bool user_gesture, |
251 bool* was_blocked) OVERRIDE { | 283 bool* was_blocked) OVERRIDE { |
252 ActivityManager::Get()->AddActivity( | 284 ActivityManager::Get()->AddActivity( |
253 new WebActivity(new AthenaWebView(new_contents))); | 285 new WebActivity(new AthenaWebView(new_contents))); |
254 } | 286 } |
255 | 287 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 return athena::OpenFileChooser(web_contents, params); | 352 return athena::OpenFileChooser(web_contents, params); |
321 } | 353 } |
322 | 354 |
323 private: | 355 private: |
324 void CreateProgressBar() { | 356 void CreateProgressBar() { |
325 CHECK(!progress_bar_); | 357 CHECK(!progress_bar_); |
326 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 358 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
327 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); | 359 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); |
328 } | 360 } |
329 | 361 |
362 void CreateReloadMessage() { | |
363 CHECK(!reload_message_); | |
364 reload_message_.reset(new views::Widget); | |
365 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | |
366 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
367 params.parent = GetWidget()->GetNativeView(); | |
368 reload_message_->Init(params); | |
369 | |
370 views::Label* label = new views::Label(base::UTF8ToUTF16("Reload")); | |
371 label->SetBackgroundColor(SK_ColorGRAY); | |
372 label->set_background( | |
373 views::Background::CreateSolidBackground(SK_ColorGRAY)); | |
374 | |
375 reload_message_->SetContentsView(label); | |
376 reload_message_->SetBounds(ConvertRectToWidget( | |
377 gfx::Rect(0, 0, width(), label->GetPreferredSize().height()))); | |
378 } | |
379 | |
330 scoped_ptr<WebActivityController> controller_; | 380 scoped_ptr<WebActivityController> controller_; |
331 | 381 |
332 // If the activity got evicted, this is the web content which holds the known | 382 // If the activity got evicted, this is the web content which holds the known |
333 // state of the content before eviction. | 383 // state of the content before eviction. |
334 scoped_ptr<content::WebContents> evicted_web_contents_; | 384 scoped_ptr<content::WebContents> evicted_web_contents_; |
335 | 385 |
336 scoped_ptr<ui::Layer> progress_bar_; | 386 scoped_ptr<ui::Layer> progress_bar_; |
337 | 387 |
388 scoped_ptr<views::Widget> reload_message_; | |
389 | |
338 // TODO(oshima): Find out if we should support window fullscreen. | 390 // TODO(oshima): Find out if we should support window fullscreen. |
339 // It may still useful when a user is in split mode. | 391 // It may still useful when a user is in split mode. |
340 bool fullscreen_; | 392 bool fullscreen_; |
341 | 393 |
394 // The distance that the user has overscrolled vertically. | |
395 int overscroll_y_; | |
396 | |
342 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); | 397 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); |
343 }; | 398 }; |
344 | 399 |
345 WebActivity::WebActivity(content::BrowserContext* browser_context, | 400 WebActivity::WebActivity(content::BrowserContext* browser_context, |
346 const base::string16& title, | 401 const base::string16& title, |
347 const GURL& url) | 402 const GURL& url) |
348 : browser_context_(browser_context), | 403 : browser_context_(browser_context), |
349 title_(title), | 404 title_(title), |
350 url_(url), | 405 url_(url), |
351 web_view_(NULL), | 406 web_view_(NULL), |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 | 643 |
589 void WebActivity::ReloadAndObserve() { | 644 void WebActivity::ReloadAndObserve() { |
590 if (web_view_->IsContentEvicted()) { | 645 if (web_view_->IsContentEvicted()) { |
591 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); | 646 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); |
592 web_view_->ReloadContent(); | 647 web_view_->ReloadContent(); |
593 } | 648 } |
594 Observe(web_view_->GetWebContents()); | 649 Observe(web_view_->GetWebContents()); |
595 } | 650 } |
596 | 651 |
597 } // namespace athena | 652 } // namespace athena |
OLD | NEW |