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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 12225163: overscroll: Show a shadow for the sliding window during nav gesture. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/browser/renderer_host/dip_util.h" 10 #include "content/browser/renderer_host/dip_util.h"
11 #include "content/browser/renderer_host/overscroll_controller.h" 11 #include "content/browser/renderer_host/overscroll_controller.h"
12 #include "content/browser/renderer_host/render_view_host_factory.h" 12 #include "content/browser/renderer_host/render_view_host_factory.h"
13 #include "content/browser/renderer_host/render_widget_host_impl.h" 13 #include "content/browser/renderer_host/render_widget_host_impl.h"
14 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 14 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
15 #include "content/browser/web_contents/interstitial_page_impl.h" 15 #include "content/browser/web_contents/interstitial_page_impl.h"
16 #include "content/browser/web_contents/navigation_entry_impl.h" 16 #include "content/browser/web_contents/navigation_entry_impl.h"
17 #include "content/browser/web_contents/web_contents_impl.h" 17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "content/public/browser/notification_observer.h" 18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 19 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
21 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/overscroll_configuration.h" 22 #include "content/public/browser/overscroll_configuration.h"
23 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host.h" 24 #include "content/public/browser/render_widget_host.h"
25 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
26 #include "content/public/browser/web_contents_delegate.h" 26 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/browser/web_contents_view_delegate.h" 27 #include "content/public/browser/web_contents_view_delegate.h"
28 #include "content/public/browser/web_drag_dest_delegate.h" 28 #include "content/public/browser/web_drag_dest_delegate.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
30 #include "third_party/skia/include/effects/SkGradientShader.h"
30 #include "ui/aura/client/aura_constants.h" 31 #include "ui/aura/client/aura_constants.h"
31 #include "ui/aura/client/drag_drop_client.h" 32 #include "ui/aura/client/drag_drop_client.h"
32 #include "ui/aura/client/drag_drop_delegate.h" 33 #include "ui/aura/client/drag_drop_delegate.h"
33 #include "ui/aura/root_window.h" 34 #include "ui/aura/root_window.h"
34 #include "ui/aura/root_window_observer.h" 35 #include "ui/aura/root_window_observer.h"
35 #include "ui/aura/window.h" 36 #include "ui/aura/window.h"
36 #include "ui/aura/window_observer.h" 37 #include "ui/aura/window_observer.h"
37 #include "ui/base/clipboard/custom_data_helper.h" 38 #include "ui/base/clipboard/custom_data_helper.h"
38 #include "ui/base/dragdrop/drag_drop_types.h" 39 #include "ui/base/dragdrop/drag_drop_types.h"
39 #include "ui/base/dragdrop/drag_utils.h" 40 #include "ui/base/dragdrop/drag_utils.h"
40 #include "ui/base/dragdrop/os_exchange_data.h" 41 #include "ui/base/dragdrop/os_exchange_data.h"
41 #include "ui/base/events/event.h" 42 #include "ui/base/events/event.h"
42 #include "ui/base/events/event_utils.h" 43 #include "ui/base/events/event_utils.h"
43 #include "ui/base/hit_test.h" 44 #include "ui/base/hit_test.h"
44 #include "ui/compositor/layer.h" 45 #include "ui/compositor/layer.h"
45 #include "ui/compositor/scoped_layer_animation_settings.h" 46 #include "ui/compositor/scoped_layer_animation_settings.h"
46 #include "ui/gfx/canvas.h" 47 #include "ui/gfx/canvas.h"
47 #include "ui/gfx/image/image.h" 48 #include "ui/gfx/image/image.h"
48 #include "ui/gfx/image/image_png_rep.h" 49 #include "ui/gfx/image/image_png_rep.h"
49 #include "ui/gfx/image/image_skia.h" 50 #include "ui/gfx/image/image_skia.h"
50 #include "ui/gfx/screen.h" 51 #include "ui/gfx/screen.h"
52 #include "ui/gfx/skia_util.h"
51 #include "webkit/glue/webdropdata.h" 53 #include "webkit/glue/webdropdata.h"
52 54
53 #if defined(OS_WIN) 55 #if defined(OS_WIN)
54 #include "ui/base/clipboard/clipboard_util_win.h" 56 #include "ui/base/clipboard/clipboard_util_win.h"
55 #endif 57 #endif
56 58
57 namespace content { 59 namespace content {
58 WebContentsView* CreateWebContentsView( 60 WebContentsView* CreateWebContentsView(
59 WebContentsImpl* web_contents, 61 WebContentsImpl* web_contents,
60 WebContentsViewDelegate* delegate, 62 WebContentsViewDelegate* delegate,
61 RenderViewHostDelegateView** render_view_host_delegate_view) { 63 RenderViewHostDelegateView** render_view_host_delegate_view) {
62 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); 64 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate);
63 *render_view_host_delegate_view = rv; 65 *render_view_host_delegate_view = rv;
64 return rv; 66 return rv;
65 } 67 }
66 68
67 namespace { 69 namespace {
68 70
71 const SkColor kShadowLightColor = SkColorSetARGB(0x0, 0, 0, 0);
72 const SkColor kShadowDarkColor = SkColorSetARGB(0x70, 0, 0, 0);
73 const int kShadowThick = 7;
74
75 enum ShadowEdge {
76 SHADOW_NONE,
77 SHADOW_LEFT,
78 SHADOW_RIGHT,
79 SHADOW_TOP,
80 SHADOW_BOTTOM
81 };
82
69 bool ShouldNavigateForward(const NavigationController& controller, 83 bool ShouldNavigateForward(const NavigationController& controller,
70 OverscrollMode mode) { 84 OverscrollMode mode) {
71 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && 85 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) &&
72 controller.CanGoForward(); 86 controller.CanGoForward();
73 } 87 }
74 88
75 bool ShouldNavigateBack(const NavigationController& controller, 89 bool ShouldNavigateBack(const NavigationController& controller,
76 OverscrollMode mode) { 90 OverscrollMode mode) {
77 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && 91 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) &&
78 controller.CanGoBack(); 92 controller.CanGoBack();
79 } 93 }
80 94
81 // The window delegate for the overscroll window. This redirects trackpad events 95 // The window delegate for the overscroll window. This redirects trackpad events
82 // to the web-contents window. The delegate destroys itself when the window is 96 // to the web-contents window. The delegate destroys itself when the window is
83 // destroyed. 97 // destroyed.
84 class OverscrollWindowDelegate : public aura::WindowDelegate { 98 class OverscrollWindowDelegate : public aura::WindowDelegate {
85 public: 99 public:
86 OverscrollWindowDelegate(WebContentsImpl* web_contents, 100 OverscrollWindowDelegate(WebContentsImpl* web_contents,
87 OverscrollMode overscroll_mode) 101 OverscrollMode overscroll_mode)
88 : web_contents_(web_contents) { 102 : web_contents_(web_contents),
103 show_shadow_(false) {
89 const NavigationControllerImpl& controller = web_contents->GetController(); 104 const NavigationControllerImpl& controller = web_contents->GetController();
90 const NavigationEntryImpl* entry = NULL; 105 const NavigationEntryImpl* entry = NULL;
91 if (ShouldNavigateForward(controller, overscroll_mode)) { 106 if (ShouldNavigateForward(controller, overscroll_mode)) {
92 entry = NavigationEntryImpl::FromNavigationEntry( 107 entry = NavigationEntryImpl::FromNavigationEntry(
93 controller.GetEntryAtOffset(1)); 108 controller.GetEntryAtOffset(1));
94 } else if (ShouldNavigateBack(controller, overscroll_mode)) { 109 } else if (ShouldNavigateBack(controller, overscroll_mode)) {
95 entry = NavigationEntryImpl::FromNavigationEntry( 110 entry = NavigationEntryImpl::FromNavigationEntry(
96 controller.GetEntryAtOffset(-1)); 111 controller.GetEntryAtOffset(-1));
97 } 112 }
98 if (!entry || !entry->screenshot()) 113 if (!entry || !entry->screenshot())
99 return; 114 return;
100 115
101 std::vector<gfx::ImagePNGRep> image_reps; 116 std::vector<gfx::ImagePNGRep> image_reps;
102 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 117 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(),
103 ui::GetScaleFactorForNativeView(web_contents_window()))); 118 ui::GetScaleFactorForNativeView(web_contents_window())));
104 image_ = gfx::Image(image_reps); 119 image_ = gfx::Image(image_reps);
105 } 120 }
106 121
107 bool has_screenshot() const { return !image_.IsEmpty(); } 122 bool has_screenshot() const { return !image_.IsEmpty(); }
108 123
124 void set_show_shadow(bool show) {
125 show_shadow_ = show;
126 }
127
109 private: 128 private:
110 virtual ~OverscrollWindowDelegate() {} 129 virtual ~OverscrollWindowDelegate() {}
111 130
112 aura::Window* web_contents_window() { 131 aura::Window* web_contents_window() {
113 return web_contents_->GetView()->GetContentNativeView(); 132 return web_contents_->GetView()->GetContentNativeView();
114 } 133 }
115 134
116 // aura::WindowDelegate implementation: 135 // aura::WindowDelegate implementation:
117 virtual gfx::Size GetMinimumSize() const OVERRIDE { 136 virtual gfx::Size GetMinimumSize() const OVERRIDE {
118 return gfx::Size(); 137 return gfx::Size();
(...skipping 22 matching lines...) Expand all
141 } 160 }
142 161
143 virtual bool CanFocus() OVERRIDE { 162 virtual bool CanFocus() OVERRIDE {
144 return false; 163 return false;
145 } 164 }
146 165
147 virtual void OnCaptureLost() OVERRIDE { 166 virtual void OnCaptureLost() OVERRIDE {
148 } 167 }
149 168
150 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 169 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
170 if (show_shadow_) {
171 canvas->Save();
172 canvas->Translate(gfx::Vector2d(kShadowThick, 0));
173 }
151 if (image_.IsEmpty()) 174 if (image_.IsEmpty())
152 canvas->DrawColor(SK_ColorGRAY); 175 canvas->DrawColor(SK_ColorGRAY);
153 else 176 else
154 canvas->DrawImageInt(image_.AsImageSkia(), 0, 0); 177 canvas->DrawImageInt(image_.AsImageSkia(), 0, 0);
178
179 if (show_shadow_) {
180 canvas->Restore();
181 SkPoint points[2];
182 points[0].iset(0, 0);
183 points[1].iset(kShadowThick, 0);
184 SkColor colors[2] = { kShadowLightColor, kShadowDarkColor };
185 skia::RefPtr<SkShader> shader = skia::AdoptRef(
186 SkGradientShader::CreateLinear(points, colors, NULL,
187 arraysize(points), SkShader::kRepeat_TileMode, NULL));
188
189 SkRect rect = { SkIntToScalar(0),
190 SkIntToScalar(0),
191 SkIntToScalar(kShadowThick),
192 SkIntToScalar(web_contents_window()->bounds().height()) };
193 SkPaint paint;
194 paint.setShader(shader.get());
195 canvas->sk_canvas()->drawRect(rect, paint);
196 }
155 } 197 }
156 198
157 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { 199 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {
158 } 200 }
159 201
160 virtual void OnWindowDestroying() OVERRIDE { 202 virtual void OnWindowDestroying() OVERRIDE {
161 } 203 }
162 204
163 virtual void OnWindowDestroyed() OVERRIDE { 205 virtual void OnWindowDestroyed() OVERRIDE {
164 delete this; 206 delete this;
(...skipping 19 matching lines...) Expand all
184 web_contents_window()->delegate()->OnScrollEvent(event); 226 web_contents_window()->delegate()->OnScrollEvent(event);
185 } 227 }
186 228
187 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 229 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
188 if (web_contents_window()) 230 if (web_contents_window())
189 web_contents_window()->delegate()->OnGestureEvent(event); 231 web_contents_window()->delegate()->OnGestureEvent(event);
190 } 232 }
191 233
192 WebContents* web_contents_; 234 WebContents* web_contents_;
193 gfx::Image image_; 235 gfx::Image image_;
236 bool show_shadow_;
194 237
195 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate); 238 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate);
196 }; 239 };
197 240
198 // Listens to all mouse drag events during a drag and drop and sends them to 241 // Listens to all mouse drag events during a drag and drop and sends them to
199 // the renderer. 242 // the renderer.
200 class WebDragSourceAura : public MessageLoopForUI::Observer, 243 class WebDragSourceAura : public MessageLoopForUI::Observer,
201 public NotificationObserver { 244 public NotificationObserver {
202 public: 245 public:
203 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) 246 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents)
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // Start resisting after the threshold. 439 // Start resisting after the threshold.
397 int resisted = threshold / 2; 440 int resisted = threshold / 2;
398 float extra = scroll - threshold; 441 float extra = scroll - threshold;
399 while ((extra /= 1.3f) > 1.f) 442 while ((extra /= 1.3f) > 1.f)
400 resisted += 1; 443 resisted += 1;
401 return resisted; 444 return resisted;
402 } 445 }
403 446
404 } // namespace 447 } // namespace
405 448
449 // ShadowWindow is used to paint shadows around a content window.
450 // A ShadowWindow destroys itself when the content window is destroyed, and
451 // updates its bounds to make sure the shadows are painted in the correct size.
452 class ShadowWindow : public aura::Window,
453 public aura::WindowObserver {
454 public:
455 explicit ShadowWindow(aura::Window* window)
456 : aura::Window(NULL),
457 window_(window),
458 edge_(SHADOW_NONE) {
459 SetType(aura::client::WINDOW_TYPE_CONTROL);
460 SetTransparent(true);
461 set_owned_by_parent(false);
462 Init(ui::LAYER_NOT_DRAWN);
463 layer()->SetMasksToBounds(false);
464
465 AddChild(window);
466 window_->AddObserver(this);
467
468 SetBounds(gfx::Rect(window->bounds().size()));
469 Show();
470 }
471
472 void SetShadowEdge(ShadowEdge edge) {
473 edge_ = edge;
474 if (edge_ == SHADOW_NONE) {
475 shadow_.reset();
476 return;
477 }
478
479 shadow_.reset(new ui::Layer(ui::LAYER_TEXTURED));
480 shadow_->set_delegate(this);
481 shadow_->SetFillsBoundsOpaquely(false);
482 layer()->Add(shadow_.get());
483 layer()->StackBelow(shadow_.get(), window_->layer());
484 UpdateShadowBounds();
485 }
486
487 private:
488 friend class base::DeleteHelper<content::ShadowWindow>;
489
490 virtual ~ShadowWindow() {
491 }
492
493 void UpdateShadowBounds() {
494 if (!shadow_.get())
495 return;
496 gfx::Rect bound;
497 switch (edge_) {
498 case SHADOW_LEFT:
499 bound.SetRect(-kShadowThick, 0, kShadowThick, bounds().height());
500 break;
501 case SHADOW_RIGHT:
502 bound.SetRect(bounds().right(), 0, kShadowThick, bounds().height());
503 break;
504 case SHADOW_TOP:
505 bound.SetRect(0, -kShadowThick, bounds().width(), kShadowThick);
506 break;
507 case SHADOW_BOTTOM:
508 bound.SetRect(0, bounds().bottom(), bounds().width(), kShadowThick);
509 break;
510 case SHADOW_NONE:
511 NOTREACHED();
512 }
513 shadow_->SetBounds(bound);
514 }
515
516 // Overridden from aura::WindowObserver:
517 virtual void OnWindowBoundsChanged(Window* window,
518 const gfx::Rect& old_bounds,
519 const gfx::Rect& new_bounds) OVERRIDE {
520 SetBounds(gfx::Rect(new_bounds.size()));
521 UpdateShadowBounds();
522 }
523
524 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
525 DCHECK_EQ(window, window_);
526 window_->RemoveObserver(this);
527 window_ = NULL;
528 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
529 }
530
531 // Overridden from ui::LayerDelegate:
532 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
533 SkPoint points[2];
534 SkColor colors[2];
535
536 points[0].iset(0, 0);
537 switch (edge_) {
538 case SHADOW_LEFT:
539 case SHADOW_RIGHT:
540 points[1].iset(shadow_->bounds().width(), 0);
541 break;
542
543 case SHADOW_TOP:
544 case SHADOW_BOTTOM:
545 points[1].iset(0, shadow_->bounds().height());
546 break;
547
548 default:
549 NOTREACHED();
550 }
551
552 switch (edge_) {
553 case SHADOW_LEFT:
554 case SHADOW_TOP:
555 colors[0] = kShadowLightColor;
556 colors[1] = kShadowDarkColor;
557 break;
558
559 case SHADOW_RIGHT:
560 case SHADOW_BOTTOM:
561 colors[0] = kShadowDarkColor;
562 colors[1] = kShadowLightColor;
563 break;
564
565 default:
566 NOTREACHED();
567 }
568
569 skia::RefPtr<SkShader> shader = skia::AdoptRef(
570 SkGradientShader::CreateLinear(points, colors, NULL,
571 arraysize(points), SkShader::kRepeat_TileMode, NULL));
572
573 SkPaint paint;
574 paint.setShader(shader.get());
575 canvas->sk_canvas()->drawRect(gfx::RectToSkRect(bounds()), paint);
576 }
577
578 aura::Window* window_;
579 scoped_ptr<ui::Layer> shadow_;
580 ShadowEdge edge_;
581
582 DISALLOW_COPY_AND_ASSIGN(ShadowWindow);
583 };
584
406 // When a history navigation is triggered at the end of an overscroll 585 // When a history navigation is triggered at the end of an overscroll
407 // navigation, it is necessary to show the history-screenshot until the page is 586 // navigation, it is necessary to show the history-screenshot until the page is
408 // done navigating and painting. This class accomplishes this by showing the 587 // done navigating and painting. This class accomplishes this by showing the
409 // screenshot window on top of the page until the page has completed loading and 588 // screenshot window on top of the page until the page has completed loading and
410 // painting. 589 // painting.
411 class OverscrollNavigationOverlay : 590 class OverscrollNavigationOverlay :
412 public RenderWidgetHostViewAura::PaintObserver { 591 public RenderWidgetHostViewAura::PaintObserver {
413 public: 592 public:
414 OverscrollNavigationOverlay() 593 OverscrollNavigationOverlay()
415 : view_(NULL), 594 : view_(NULL),
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 // WebContentsViewAura, public: 745 // WebContentsViewAura, public:
567 746
568 WebContentsViewAura::WebContentsViewAura( 747 WebContentsViewAura::WebContentsViewAura(
569 WebContentsImpl* web_contents, 748 WebContentsImpl* web_contents,
570 WebContentsViewDelegate* delegate) 749 WebContentsViewDelegate* delegate)
571 : web_contents_(web_contents), 750 : web_contents_(web_contents),
572 delegate_(delegate), 751 delegate_(delegate),
573 current_drag_op_(WebKit::WebDragOperationNone), 752 current_drag_op_(WebKit::WebDragOperationNone),
574 drag_dest_delegate_(NULL), 753 drag_dest_delegate_(NULL),
575 current_rvh_for_drag_(NULL), 754 current_rvh_for_drag_(NULL),
755 content_container_(NULL),
576 overscroll_change_brightness_(false), 756 overscroll_change_brightness_(false),
577 current_overscroll_gesture_(OVERSCROLL_NONE), 757 current_overscroll_gesture_(OVERSCROLL_NONE),
578 completed_overscroll_gesture_(OVERSCROLL_NONE) { 758 completed_overscroll_gesture_(OVERSCROLL_NONE) {
579 } 759 }
580 760
581 //////////////////////////////////////////////////////////////////////////////// 761 ////////////////////////////////////////////////////////////////////////////////
582 // WebContentsViewAura, private: 762 // WebContentsViewAura, private:
583 763
584 WebContentsViewAura::~WebContentsViewAura() { 764 WebContentsViewAura::~WebContentsViewAura() {
585 if (!window_) 765 if (!window_)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 base::AutoReset<OverscrollMode> reset_state(&current_overscroll_gesture_, 802 base::AutoReset<OverscrollMode> reset_state(&current_overscroll_gesture_,
623 current_overscroll_gesture_); 803 current_overscroll_gesture_);
624 scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); 804 scoped_ptr<aura::Window> reset_window(overscroll_window_.release());
625 } 805 }
626 806
627 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( 807 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate(
628 web_contents_, 808 web_contents_,
629 current_overscroll_gesture_); 809 current_overscroll_gesture_);
630 overscroll_window_.reset(new aura::Window(overscroll_delegate)); 810 overscroll_window_.reset(new aura::Window(overscroll_delegate));
631 overscroll_window_->SetType(aura::client::WINDOW_TYPE_CONTROL); 811 overscroll_window_->SetType(aura::client::WINDOW_TYPE_CONTROL);
632 overscroll_window_->SetTransparent(false); 812 overscroll_window_->SetTransparent(true);
633 overscroll_window_->Init(ui::LAYER_TEXTURED); 813 overscroll_window_->Init(ui::LAYER_TEXTURED);
634 overscroll_window_->layer()->SetMasksToBounds(true); 814 overscroll_window_->layer()->SetMasksToBounds(true);
635 overscroll_window_->SetName("OverscrollOverlay"); 815 overscroll_window_->SetName("OverscrollOverlay");
636 816
637 overscroll_change_brightness_ = overscroll_delegate->has_screenshot(); 817 overscroll_change_brightness_ = overscroll_delegate->has_screenshot();
638 window_->AddChild(overscroll_window_.get()); 818 window_->AddChild(overscroll_window_.get());
639 819
640 gfx::Rect bounds = gfx::Rect(window_->bounds().size()); 820 gfx::Rect bounds = gfx::Rect(window_->bounds().size());
641 if (ShouldNavigateForward(web_contents_->GetController(), 821 if (ShouldNavigateForward(web_contents_->GetController(),
642 current_overscroll_gesture_)) { 822 current_overscroll_gesture_)) {
643 // The overlay will be sliding in from the right edge towards the left in 823 // The overlay will be sliding in from the right edge towards the left in
644 // non-RTL, or sliding in from the left edge towards the right in RTL. 824 // non-RTL, or sliding in from the left edge towards the right in RTL.
645 // So position the overlay window accordingly. 825 // So position the overlay window accordingly.
646 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0); 826 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0);
647 } 827 }
648 828
649 if (GetWindowToAnimateForOverscroll() == overscroll_window_.get()) 829 if (GetWindowToAnimateForOverscroll() == overscroll_window_.get()) {
650 window_->StackChildAbove(overscroll_window_.get(), GetContentNativeView()); 830 overscroll_delegate->set_show_shadow(true);
651 else 831 window_->StackChildAbove(overscroll_window_.get(), content_container_);
652 window_->StackChildBelow(overscroll_window_.get(), GetContentNativeView()); 832 } else {
833 window_->StackChildBelow(overscroll_window_.get(), content_container_);
834
835 switch (current_overscroll_gesture_) {
836 case OVERSCROLL_EAST:
837 content_container_->SetShadowEdge(SHADOW_LEFT);
838 break;
839
840 case OVERSCROLL_WEST:
841 content_container_->SetShadowEdge(SHADOW_RIGHT);
842 break;
843
844 case OVERSCROLL_NORTH:
845 content_container_->SetShadowEdge(SHADOW_BOTTOM);
846 break;
847
848 case OVERSCROLL_SOUTH:
849 content_container_->SetShadowEdge(SHADOW_TOP);
850 break;
851
852 case OVERSCROLL_NONE:
853 case OVERSCROLL_COUNT:
854 NOTREACHED();
855 }
856 }
653 857
654 UpdateOverscrollWindowBrightness(0.f); 858 UpdateOverscrollWindowBrightness(0.f);
655 859
656 overscroll_window_->SetBounds(bounds); 860 overscroll_window_->SetBounds(bounds);
657 overscroll_window_->Show(); 861 overscroll_window_->Show();
658 } 862 }
659 863
660 void WebContentsViewAura::PrepareContentWindowForOverscroll() { 864 void WebContentsViewAura::PrepareContentWindowForOverscroll() {
661 aura::Window* content = GetContentNativeView(); 865 aura::Window* content = content_container_;
662 if (!content) 866 if (!content)
663 return; 867 return;
664 868
665 ui::ScopedLayerAnimationSettings settings(content->layer()->GetAnimator()); 869 ui::ScopedLayerAnimationSettings settings(content->layer()->GetAnimator());
666 settings.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET); 870 settings.SetPreemptionStrategy(ui::LayerAnimator::IMMEDIATELY_SET_NEW_TARGET);
667 content->SetTransform(gfx::Transform()); 871 content->SetTransform(gfx::Transform());
668 content->layer()->SetLayerBrightness(0.f); 872 content->layer()->SetLayerBrightness(0.f);
669 } 873 }
670 874
671 void WebContentsViewAura::ResetOverscrollTransform() { 875 void WebContentsViewAura::ResetOverscrollTransform() {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 target->SetTransform(transform); 922 target->SetTransform(transform);
719 UpdateOverscrollWindowBrightness(translate_x); 923 UpdateOverscrollWindowBrightness(translate_x);
720 } 924 }
721 925
722 aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() { 926 aura::Window* WebContentsViewAura::GetWindowToAnimateForOverscroll() {
723 if (current_overscroll_gesture_ == OVERSCROLL_NONE) 927 if (current_overscroll_gesture_ == OVERSCROLL_NONE)
724 return NULL; 928 return NULL;
725 929
726 return ShouldNavigateForward(web_contents_->GetController(), 930 return ShouldNavigateForward(web_contents_->GetController(),
727 current_overscroll_gesture_) ? 931 current_overscroll_gesture_) ?
728 overscroll_window_.get() : GetContentNativeView(); 932 overscroll_window_.get() : content_container_;
729 } 933 }
730 934
731 gfx::Vector2d WebContentsViewAura::GetTranslationForOverscroll(int delta_x, 935 gfx::Vector2d WebContentsViewAura::GetTranslationForOverscroll(int delta_x,
732 int delta_y) { 936 int delta_y) {
733 if (current_overscroll_gesture_ == OVERSCROLL_NORTH || 937 if (current_overscroll_gesture_ == OVERSCROLL_NORTH ||
734 current_overscroll_gesture_ == OVERSCROLL_SOUTH) { 938 current_overscroll_gesture_ == OVERSCROLL_SOUTH) {
735 // For vertical overscroll, always do a resisted drag. 939 // For vertical overscroll, always do a resisted drag.
736 const float threshold = GetOverscrollConfig( 940 const float threshold = GetOverscrollConfig(
737 OVERSCROLL_CONFIG_VERT_RESIST_AFTER); 941 OVERSCROLL_CONFIG_VERT_RESIST_AFTER);
738 int scroll = GetResistedScrollAmount(abs(delta_y), 942 int scroll = GetResistedScrollAmount(abs(delta_y),
(...skipping 11 matching lines...) Expand all
750 return gfx::Vector2d(std::min(bounds.width(), delta_x), 0); 954 return gfx::Vector2d(std::min(bounds.width(), delta_x), 0);
751 955
752 const float threshold = GetOverscrollConfig( 956 const float threshold = GetOverscrollConfig(
753 OVERSCROLL_CONFIG_HORIZ_RESIST_AFTER); 957 OVERSCROLL_CONFIG_HORIZ_RESIST_AFTER);
754 int scroll = GetResistedScrollAmount(abs(delta_x), 958 int scroll = GetResistedScrollAmount(abs(delta_x),
755 static_cast<int>(threshold)); 959 static_cast<int>(threshold));
756 return gfx::Vector2d(delta_x < 0 ? -scroll : scroll, 0); 960 return gfx::Vector2d(delta_x < 0 ? -scroll : scroll, 0);
757 } 961 }
758 962
759 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() { 963 void WebContentsViewAura::PrepareOverscrollNavigationOverlay() {
964 OverscrollWindowDelegate* delegate = static_cast<OverscrollWindowDelegate*>(
965 overscroll_window_->delegate());
966 delegate->set_show_shadow(false);
967 overscroll_window_->SchedulePaintInRect(
968 gfx::Rect(overscroll_window_->bounds().size()));
760 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass()); 969 navigation_overlay_->SetOverlayWindow(overscroll_window_.Pass());
761 navigation_overlay_->StartObservingView(static_cast< 970 navigation_overlay_->StartObservingView(static_cast<
762 RenderWidgetHostViewAura*>(web_contents_->GetRenderWidgetHostView())); 971 RenderWidgetHostViewAura*>(web_contents_->GetRenderWidgetHostView()));
763 } 972 }
764 973
765 void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) { 974 void WebContentsViewAura::UpdateOverscrollWindowBrightness(float delta_x) {
766 if (!overscroll_change_brightness_) 975 if (!overscroll_change_brightness_)
767 return; 976 return;
768 977
769 const float kBrightnessMin = -.5f; 978 const float kBrightnessMin = -.5f;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // this actually is happening (and somebody isn't accidentally creating the 1037 // this actually is happening (and somebody isn't accidentally creating the
829 // view twice), we check for the RVH Factory, which will be set when we're 1038 // view twice), we check for the RVH Factory, which will be set when we're
830 // making special ones (which go along with the special views). 1039 // making special ones (which go along with the special views).
831 DCHECK(RenderViewHostFactory::has_factory()); 1040 DCHECK(RenderViewHostFactory::has_factory());
832 return render_widget_host->GetView(); 1041 return render_widget_host->GetView();
833 } 1042 }
834 1043
835 RenderWidgetHostView* view = 1044 RenderWidgetHostView* view =
836 RenderWidgetHostView::CreateViewForWidget(render_widget_host); 1045 RenderWidgetHostView::CreateViewForWidget(render_widget_host);
837 view->InitAsChild(NULL); 1046 view->InitAsChild(NULL);
838 GetNativeView()->AddChild(view->GetNativeView()); 1047 content_container_ = new ShadowWindow(view->GetNativeView());
1048 GetNativeView()->AddChild(content_container_);
839 1049
840 if (navigation_overlay_.get() && navigation_overlay_->has_window()) { 1050 if (navigation_overlay_.get() && navigation_overlay_->has_window()) {
841 navigation_overlay_->StartObservingView(static_cast< 1051 navigation_overlay_->StartObservingView(static_cast<
842 RenderWidgetHostViewAura*>(view)); 1052 RenderWidgetHostViewAura*>(view));
843 } 1053 }
844 1054
845 view->Show(); 1055 view->Show();
846 1056
847 // We listen to drag drop events in the newly created view's window. 1057 // We listen to drag drop events in the newly created view's window.
848 aura::client::SetDragDropDelegate(view->GetNativeView(), this); 1058 aura::client::SetDragDropDelegate(view->GetNativeView(), this);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 completed_overscroll_gesture_)) { 1308 completed_overscroll_gesture_)) {
1099 PrepareOverscrollNavigationOverlay(); 1309 PrepareOverscrollNavigationOverlay();
1100 web_contents_->GetController().GoForward(); 1310 web_contents_->GetController().GoForward();
1101 } else if (ShouldNavigateBack(web_contents_->GetController(), 1311 } else if (ShouldNavigateBack(web_contents_->GetController(),
1102 completed_overscroll_gesture_)) { 1312 completed_overscroll_gesture_)) {
1103 PrepareOverscrollNavigationOverlay(); 1313 PrepareOverscrollNavigationOverlay();
1104 web_contents_->GetController().GoBack(); 1314 web_contents_->GetController().GoBack();
1105 } 1315 }
1106 1316
1107 if (GetContentNativeView()) { 1317 if (GetContentNativeView()) {
1108 GetContentNativeView()->SetTransform(gfx::Transform()); 1318 content_container_->SetTransform(gfx::Transform());
1109 GetContentNativeView()->layer()->SetLayerBrightness(0.f); 1319 content_container_->layer()->SetLayerBrightness(0.f);
1320 content_container_->SetShadowEdge(SHADOW_NONE);
1110 } 1321 }
1111 current_overscroll_gesture_ = OVERSCROLL_NONE; 1322 current_overscroll_gesture_ = OVERSCROLL_NONE;
1112 completed_overscroll_gesture_ = OVERSCROLL_NONE; 1323 completed_overscroll_gesture_ = OVERSCROLL_NONE;
1113 overscroll_window_.reset(); 1324 overscroll_window_.reset();
1114 } 1325 }
1115 1326
1116 //////////////////////////////////////////////////////////////////////////////// 1327 ////////////////////////////////////////////////////////////////////////////////
1117 // WebContentsViewAura, aura::WindowDelegate implementation: 1328 // WebContentsViewAura, aura::WindowDelegate implementation:
1118 1329
1119 gfx::Size WebContentsViewAura::GetMinimumSize() const { 1330 gfx::Size WebContentsViewAura::GetMinimumSize() const {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 event.location(), 1507 event.location(),
1297 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1508 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1298 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1509 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1299 if (drag_dest_delegate_) 1510 if (drag_dest_delegate_)
1300 drag_dest_delegate_->OnDrop(); 1511 drag_dest_delegate_->OnDrop();
1301 current_drop_data_.reset(); 1512 current_drop_data_.reset();
1302 return current_drag_op_; 1513 return current_drag_op_;
1303 } 1514 }
1304 1515
1305 } // namespace content 1516 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698