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

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

Issue 554393008: [Athena] Simple pull to refresh implementation (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/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 "content/public/browser/native_web_keyboard_event.h" 14 #include "content/public/browser/native_web_keyboard_event.h"
15 #include "content/public/browser/navigation_controller.h" 15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_delegate.h" 17 #include "content/public/browser/web_contents_delegate.h"
18 #include "content/public/common/content_switches.h" 18 #include "content/public/common/content_switches.h"
19 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
20 #include "ui/compositor/closure_animation_observer.h" 20 #include "ui/compositor/closure_animation_observer.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h" 21 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/views/background.h"
23 #include "ui/views/controls/label.h"
22 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" 24 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
23 #include "ui/views/controls/webview/webview.h" 25 #include "ui/views/controls/webview/webview.h"
24 #include "ui/views/focus/focus_manager.h" 26 #include "ui/views/focus/focus_manager.h"
25 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
26 28
27 namespace athena { 29 namespace athena {
28 namespace { 30 namespace {
29 31
30 class WebActivityController : public AcceleratorHandler { 32 class WebActivityController : public AcceleratorHandler {
31 public: 33 public:
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 views::WebView* web_view_; 141 views::WebView* web_view_;
140 bool reserved_accelerator_enabled_; 142 bool reserved_accelerator_enabled_;
141 scoped_ptr<AcceleratorManager> accelerator_manager_; 143 scoped_ptr<AcceleratorManager> accelerator_manager_;
142 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; 144 views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
143 145
144 DISALLOW_COPY_AND_ASSIGN(WebActivityController); 146 DISALLOW_COPY_AND_ASSIGN(WebActivityController);
145 }; 147 };
146 148
147 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2); 149 const SkColor kDefaultTitleColor = SkColorSetRGB(0xf2, 0xf2, 0xf2);
148 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77); 150 const SkColor kDefaultUnavailableColor = SkColorSetRGB(0xbb, 0x77, 0x77);
151 const int kDistanceShowReloadMessage = 30;
152 const int kDistanceReload = 70;
149 153
150 } // namespace 154 } // namespace
151 155
152 // A web view for athena's web activity. Note that AthenaWebView will create its 156 // A web view for athena's web activity. Note that AthenaWebView will create its
153 // own content so that it can eject and reload it. 157 // own content so that it can eject and reload it.
154 class AthenaWebView : public views::WebView { 158 class AthenaWebView : public views::WebView {
155 public: 159 public:
156 AthenaWebView(content::BrowserContext* context) 160 AthenaWebView(content::BrowserContext* context)
157 : views::WebView(context), controller_(new WebActivityController(this)), 161 : views::WebView(context), controller_(new WebActivityController(this)),
158 fullscreen_(false) { 162 fullscreen_(false),
163 overscroll_y_(0) {
159 SetEmbedFullscreenWidgetMode(true); 164 SetEmbedFullscreenWidgetMode(true);
160 // TODO(skuhne): Add content observer to detect renderer crash and set 165 // TODO(skuhne): Add content observer to detect renderer crash and set
161 // content status to unloaded if that happens. 166 // content status to unloaded if that happens.
162 } 167 }
163 168
164 AthenaWebView(content::WebContents* web_contents) 169 AthenaWebView(content::WebContents* web_contents)
165 : views::WebView(web_contents->GetBrowserContext()), 170 : views::WebView(web_contents->GetBrowserContext()),
166 controller_(new WebActivityController(this)) { 171 controller_(new WebActivityController(this)) {
167 scoped_ptr<content::WebContents> old_contents( 172 scoped_ptr<content::WebContents> old_contents(
168 SwapWebContents(scoped_ptr<content::WebContents>(web_contents))); 173 SwapWebContents(scoped_ptr<content::WebContents>(web_contents)));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 // NULL is returned if the URL wasn't opened immediately. 238 // NULL is returned if the URL wasn't opened immediately.
234 return NULL; 239 return NULL;
235 } 240 }
236 241
237 virtual bool CanOverscrollContent() const OVERRIDE { 242 virtual bool CanOverscrollContent() const OVERRIDE {
238 const std::string value = CommandLine::ForCurrentProcess()-> 243 const std::string value = CommandLine::ForCurrentProcess()->
239 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); 244 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation);
240 return value != "0"; 245 return value != "0";
241 } 246 }
242 247
248 virtual void OverscrollUpdate(int delta_y) OVERRIDE {
249 overscroll_y_ = delta_y;
250 if (overscroll_y_ > kDistanceShowReloadMessage) {
251 if (!reload_message_)
252 CreateReloadMessage();
253 reload_message_->Show();
254 float opacity = (overscroll_y_ - kDistanceReload) /
255 static_cast<float>(kDistanceReload - kDistanceShowReloadMessage);
256 reload_message_->GetLayer()->SetOpacity(std::min(1.0f, opacity));
sadrul 2014/09/11 04:33:14 opacity will be negative when overscroll_y_ < kDis
pkotwicz 2014/09/11 22:51:40 Thanks for catching this. I cannot use gfx::Tween
257 } else if (reload_message_) {
258 reload_message_->Hide();
259 }
260 }
261
262 virtual void OverscrollComplete() OVERRIDE {
263 if (overscroll_y_ >= kDistanceReload) {
264 reload_message_->Hide();
265 overscroll_y_ = 0;
266
267 GetWebContents()->GetController().Reload(false);
268 }
269 }
270
243 virtual void AddNewContents(content::WebContents* source, 271 virtual void AddNewContents(content::WebContents* source,
244 content::WebContents* new_contents, 272 content::WebContents* new_contents,
245 WindowOpenDisposition disposition, 273 WindowOpenDisposition disposition,
246 const gfx::Rect& initial_pos, 274 const gfx::Rect& initial_pos,
247 bool user_gesture, 275 bool user_gesture,
248 bool* was_blocked) OVERRIDE { 276 bool* was_blocked) OVERRIDE {
249 ActivityManager::Get()->AddActivity( 277 ActivityManager::Get()->AddActivity(
250 new WebActivity(new AthenaWebView(new_contents))); 278 new WebActivity(new AthenaWebView(new_contents)));
251 } 279 }
252 280
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 return athena::OpenFileChooser(web_contents, params); 345 return athena::OpenFileChooser(web_contents, params);
318 } 346 }
319 347
320 private: 348 private:
321 void CreateProgressBar() { 349 void CreateProgressBar() {
322 CHECK(!progress_bar_); 350 CHECK(!progress_bar_);
323 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); 351 progress_bar_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
324 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd)); 352 progress_bar_->SetColor(SkColorSetRGB(0x17, 0x59, 0xcd));
325 } 353 }
326 354
355 void CreateReloadMessage() {
356 CHECK(!reload_message_);
357 reload_message_.reset(new views::Widget);
358 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
359 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
360 params.parent = GetWidget()->GetNativeView();
361 reload_message_->Init(params);
362
363 views::Label* label = new views::Label(base::UTF8ToUTF16("Reload"));
364 label->SetBackgroundColor(SK_ColorGRAY);
365 label->set_background(
366 views::Background::CreateSolidBackground(SK_ColorGRAY));
367
368 reload_message_->SetContentsView(label);
369 reload_message_->SetBounds(ConvertRectToWidget(
370 gfx::Rect(0, 0, width(), label->GetPreferredSize().height())));
371 }
372
327 scoped_ptr<WebActivityController> controller_; 373 scoped_ptr<WebActivityController> controller_;
328 374
329 // If the activity got evicted, this is the web content which holds the known 375 // If the activity got evicted, this is the web content which holds the known
330 // state of the content before eviction. 376 // state of the content before eviction.
331 scoped_ptr<content::WebContents> evicted_web_contents_; 377 scoped_ptr<content::WebContents> evicted_web_contents_;
332 378
333 scoped_ptr<ui::Layer> progress_bar_; 379 scoped_ptr<ui::Layer> progress_bar_;
334 380
381 scoped_ptr<views::Widget> reload_message_;
382
335 // TODO(oshima): Find out if we should support window fullscreen. 383 // TODO(oshima): Find out if we should support window fullscreen.
336 // It may still useful when a user is in split mode. 384 // It may still useful when a user is in split mode.
337 bool fullscreen_; 385 bool fullscreen_;
338 386
387 // The distance that the user has overscrolled vertically.
388 int overscroll_y_;
389
339 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); 390 DISALLOW_COPY_AND_ASSIGN(AthenaWebView);
340 }; 391 };
341 392
342 WebActivity::WebActivity(content::BrowserContext* browser_context, 393 WebActivity::WebActivity(content::BrowserContext* browser_context,
343 const base::string16& title, 394 const base::string16& title,
344 const GURL& url) 395 const GURL& url)
345 : browser_context_(browser_context), 396 : browser_context_(browser_context),
346 title_(title), 397 title_(title),
347 url_(url), 398 url_(url),
348 web_view_(NULL), 399 web_view_(NULL),
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 592
542 void WebActivity::ReloadAndObserve() { 593 void WebActivity::ReloadAndObserve() {
543 if (web_view_->IsContentEvicted()) { 594 if (web_view_->IsContentEvicted()) {
544 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_); 595 DCHECK_EQ(ACTIVITY_UNLOADED, current_state_);
545 web_view_->ReloadContent(); 596 web_view_->ReloadContent();
546 } 597 }
547 Observe(web_view_->GetWebContents()); 598 Observe(web_view_->GetWebContents());
548 } 599 }
549 600
550 } // namespace athena 601 } // namespace athena
OLDNEW
« no previous file with comments | « no previous file | athena/main/athena_launcher.cc » ('j') | content/browser/web_contents/web_contents_view_aura.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698