| OLD | NEW |
| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 std::vector<gfx::ImagePNGRep> image_reps; | 137 std::vector<gfx::ImagePNGRep> image_reps; |
| 138 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); | 138 image_reps.push_back(gfx::ImagePNGRep(entry->screenshot(), 1.0f)); |
| 139 image = gfx::Image(image_reps); | 139 image = gfx::Image(image_reps); |
| 140 } | 140 } |
| 141 SetImage(image); | 141 SetImage(image); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void stop_forwarding_events() { forward_events_ = false; } | 144 void stop_forwarding_events() { forward_events_ = false; } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 virtual ~OverscrollWindowDelegate() {} | 147 ~OverscrollWindowDelegate() override {} |
| 148 | 148 |
| 149 aura::Window* web_contents_window() { | 149 aura::Window* web_contents_window() { |
| 150 return web_contents_->GetView()->GetContentNativeView(); | 150 return web_contents_->GetView()->GetContentNativeView(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Overridden from ui::EventHandler. | 153 // Overridden from ui::EventHandler. |
| 154 virtual void OnScrollEvent(ui::ScrollEvent* event) override { | 154 void OnScrollEvent(ui::ScrollEvent* event) override { |
| 155 if (forward_events_ && web_contents_window()) | 155 if (forward_events_ && web_contents_window()) |
| 156 web_contents_window()->delegate()->OnScrollEvent(event); | 156 web_contents_window()->delegate()->OnScrollEvent(event); |
| 157 } | 157 } |
| 158 | 158 |
| 159 virtual void OnGestureEvent(ui::GestureEvent* event) override { | 159 void OnGestureEvent(ui::GestureEvent* event) override { |
| 160 if (forward_events_ && web_contents_window()) | 160 if (forward_events_ && web_contents_window()) |
| 161 web_contents_window()->delegate()->OnGestureEvent(event); | 161 web_contents_window()->delegate()->OnGestureEvent(event); |
| 162 } | 162 } |
| 163 | 163 |
| 164 WebContentsImpl* web_contents_; | 164 WebContentsImpl* web_contents_; |
| 165 | 165 |
| 166 // The window is displayed both during the gesture, and after the gesture | 166 // The window is displayed both during the gesture, and after the gesture |
| 167 // while the navigation is in progress. During the gesture, it is necessary to | 167 // while the navigation is in progress. During the gesture, it is necessary to |
| 168 // forward input events to the content page (e.g. when the overscroll window | 168 // forward input events to the content page (e.g. when the overscroll window |
| 169 // slides under the cursor and starts receiving scroll events). However, once | 169 // slides under the cursor and starts receiving scroll events). However, once |
| 170 // the gesture is complete, and the window is being displayed as an overlay | 170 // the gesture is complete, and the window is being displayed as an overlay |
| 171 // window during navigation, events should not be forwarded anymore. | 171 // window during navigation, events should not be forwarded anymore. |
| 172 bool forward_events_; | 172 bool forward_events_; |
| 173 | 173 |
| 174 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate); | 174 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegate); |
| 175 }; | 175 }; |
| 176 | 176 |
| 177 // Listens to all mouse drag events during a drag and drop and sends them to | 177 // Listens to all mouse drag events during a drag and drop and sends them to |
| 178 // the renderer. | 178 // the renderer. |
| 179 class WebDragSourceAura : public NotificationObserver { | 179 class WebDragSourceAura : public NotificationObserver { |
| 180 public: | 180 public: |
| 181 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) | 181 WebDragSourceAura(aura::Window* window, WebContentsImpl* contents) |
| 182 : window_(window), | 182 : window_(window), |
| 183 contents_(contents) { | 183 contents_(contents) { |
| 184 registrar_.Add(this, | 184 registrar_.Add(this, |
| 185 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, | 185 NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 186 Source<WebContents>(contents)); | 186 Source<WebContents>(contents)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 virtual ~WebDragSourceAura() { | 189 ~WebDragSourceAura() override {} |
| 190 } | |
| 191 | 190 |
| 192 // NotificationObserver: | 191 // NotificationObserver: |
| 193 virtual void Observe(int type, | 192 void Observe(int type, |
| 194 const NotificationSource& source, | 193 const NotificationSource& source, |
| 195 const NotificationDetails& details) override { | 194 const NotificationDetails& details) override { |
| 196 if (type != NOTIFICATION_WEB_CONTENTS_DISCONNECTED) | 195 if (type != NOTIFICATION_WEB_CONTENTS_DISCONNECTED) |
| 197 return; | 196 return; |
| 198 | 197 |
| 199 // Cancel the drag if it is still in progress. | 198 // Cancel the drag if it is still in progress. |
| 200 aura::client::DragDropClient* dnd_client = | 199 aura::client::DragDropClient* dnd_client = |
| 201 aura::client::GetDragDropClient(window_->GetRootWindow()); | 200 aura::client::GetDragDropClient(window_->GetRootWindow()); |
| 202 if (dnd_client && dnd_client->IsDragDropInProgress()) | 201 if (dnd_client && dnd_client->IsDragDropInProgress()) |
| 203 dnd_client->DragCancel(); | 202 dnd_client->DragCancel(); |
| 204 | 203 |
| 205 window_ = NULL; | 204 window_ = NULL; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 : view_(view), | 471 : view_(view), |
| 473 host_window_(NULL) { | 472 host_window_(NULL) { |
| 474 view_->window_->AddObserver(this); | 473 view_->window_->AddObserver(this); |
| 475 | 474 |
| 476 #if defined(OS_WIN) | 475 #if defined(OS_WIN) |
| 477 if (view_->window_->GetRootWindow()) | 476 if (view_->window_->GetRootWindow()) |
| 478 view_->window_->GetRootWindow()->AddObserver(this); | 477 view_->window_->GetRootWindow()->AddObserver(this); |
| 479 #endif | 478 #endif |
| 480 } | 479 } |
| 481 | 480 |
| 482 virtual ~WindowObserver() { | 481 ~WindowObserver() override { |
| 483 view_->window_->RemoveObserver(this); | 482 view_->window_->RemoveObserver(this); |
| 484 if (view_->window_->GetHost()) | 483 if (view_->window_->GetHost()) |
| 485 view_->window_->GetHost()->RemoveObserver(this); | 484 view_->window_->GetHost()->RemoveObserver(this); |
| 486 if (host_window_) | 485 if (host_window_) |
| 487 host_window_->RemoveObserver(this); | 486 host_window_->RemoveObserver(this); |
| 488 #if defined(OS_WIN) | 487 #if defined(OS_WIN) |
| 489 if (host_window_) { | 488 if (host_window_) { |
| 490 const aura::Window::Windows& children = host_window_->children(); | 489 const aura::Window::Windows& children = host_window_->children(); |
| 491 for (size_t i = 0; i < children.size(); ++i) | 490 for (size_t i = 0; i < children.size(); ++i) |
| 492 children[i]->RemoveObserver(this); | 491 children[i]->RemoveObserver(this); |
| 493 } | 492 } |
| 494 | 493 |
| 495 aura::Window* root_window = view_->window_->GetRootWindow(); | 494 aura::Window* root_window = view_->window_->GetRootWindow(); |
| 496 if (root_window) { | 495 if (root_window) { |
| 497 root_window->RemoveObserver(this); | 496 root_window->RemoveObserver(this); |
| 498 const aura::Window::Windows& root_children = root_window->children(); | 497 const aura::Window::Windows& root_children = root_window->children(); |
| 499 for (size_t i = 0; i < root_children.size(); ++i) | 498 for (size_t i = 0; i < root_children.size(); ++i) |
| 500 root_children[i]->RemoveObserver(this); | 499 root_children[i]->RemoveObserver(this); |
| 501 } | 500 } |
| 502 #endif | 501 #endif |
| 503 } | 502 } |
| 504 | 503 |
| 505 // Overridden from aura::WindowObserver: | 504 // Overridden from aura::WindowObserver: |
| 506 virtual void OnWindowHierarchyChanged( | 505 void OnWindowHierarchyChanged( |
| 507 const aura::WindowObserver::HierarchyChangeParams& params) override { | 506 const aura::WindowObserver::HierarchyChangeParams& params) override { |
| 508 if (params.receiver != view_->window_.get() || | 507 if (params.receiver != view_->window_.get() || |
| 509 !params.target->Contains(view_->window_.get())) { | 508 !params.target->Contains(view_->window_.get())) { |
| 510 return; | 509 return; |
| 511 } | 510 } |
| 512 | 511 |
| 513 // Use the new parent's root window for calculating HiDPI subpixel offset. | 512 // Use the new parent's root window for calculating HiDPI subpixel offset. |
| 514 RenderWidgetHostViewAura* rwhv = ToRenderWidgetHostViewAura( | 513 RenderWidgetHostViewAura* rwhv = ToRenderWidgetHostViewAura( |
| 515 view_->web_contents_->GetRenderWidgetHostView()); | 514 view_->web_contents_->GetRenderWidgetHostView()); |
| 516 if (rwhv) | 515 if (rwhv) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 virtual void OnWindowVisibilityChanged(aura::Window* window, | 552 virtual void OnWindowVisibilityChanged(aura::Window* window, |
| 554 bool visible) override { | 553 bool visible) override { |
| 555 if (window == view_->window_ || | 554 if (window == view_->window_ || |
| 556 window->parent() == host_window_ || | 555 window->parent() == host_window_ || |
| 557 window->parent() == view_->window_->GetRootWindow()) { | 556 window->parent() == view_->window_->GetRootWindow()) { |
| 558 UpdateConstrainedWindows(NULL); | 557 UpdateConstrainedWindows(NULL); |
| 559 } | 558 } |
| 560 } | 559 } |
| 561 #endif | 560 #endif |
| 562 | 561 |
| 563 virtual void OnWindowParentChanged(aura::Window* window, | 562 void OnWindowParentChanged(aura::Window* window, |
| 564 aura::Window* parent) override { | 563 aura::Window* parent) override { |
| 565 if (window != view_->window_) | 564 if (window != view_->window_) |
| 566 return; | 565 return; |
| 567 | 566 |
| 568 aura::Window* host_window = | 567 aura::Window* host_window = |
| 569 window->GetProperty(aura::client::kHostWindowKey); | 568 window->GetProperty(aura::client::kHostWindowKey); |
| 570 if (!host_window) | 569 if (!host_window) |
| 571 host_window = parent; | 570 host_window = parent; |
| 572 | 571 |
| 573 if (host_window_) | 572 if (host_window_) |
| 574 host_window_->RemoveObserver(this); | 573 host_window_->RemoveObserver(this); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 const aura::Window::Windows& children = host_window->children(); | 607 const aura::Window::Windows& children = host_window->children(); |
| 609 for (size_t i = 0; i < children.size(); ++i) { | 608 for (size_t i = 0; i < children.size(); ++i) { |
| 610 if (!children[i]->Contains(view_->window_.get())) | 609 if (!children[i]->Contains(view_->window_.get())) |
| 611 children[i]->AddObserver(this); | 610 children[i]->AddObserver(this); |
| 612 } | 611 } |
| 613 } | 612 } |
| 614 #endif | 613 #endif |
| 615 } | 614 } |
| 616 } | 615 } |
| 617 | 616 |
| 618 virtual void OnWindowBoundsChanged(aura::Window* window, | 617 void OnWindowBoundsChanged(aura::Window* window, |
| 619 const gfx::Rect& old_bounds, | 618 const gfx::Rect& old_bounds, |
| 620 const gfx::Rect& new_bounds) override { | 619 const gfx::Rect& new_bounds) override { |
| 621 if (window == host_window_ || window == view_->window_) { | 620 if (window == host_window_ || window == view_->window_) { |
| 622 SendScreenRects(); | 621 SendScreenRects(); |
| 623 if (view_->touch_editable_) | 622 if (view_->touch_editable_) |
| 624 view_->touch_editable_->UpdateEditingController(); | 623 view_->touch_editable_->UpdateEditingController(); |
| 625 #if defined(OS_WIN) | 624 #if defined(OS_WIN) |
| 626 } else { | 625 } else { |
| 627 UpdateConstrainedWindows(NULL); | 626 UpdateConstrainedWindows(NULL); |
| 628 #endif | 627 #endif |
| 629 } | 628 } |
| 630 } | 629 } |
| 631 | 630 |
| 632 virtual void OnWindowDestroying(aura::Window* window) override { | 631 void OnWindowDestroying(aura::Window* window) override { |
| 633 if (window == host_window_) { | 632 if (window == host_window_) { |
| 634 host_window_->RemoveObserver(this); | 633 host_window_->RemoveObserver(this); |
| 635 host_window_ = NULL; | 634 host_window_ = NULL; |
| 636 } | 635 } |
| 637 } | 636 } |
| 638 | 637 |
| 639 virtual void OnWindowAddedToRootWindow(aura::Window* window) override { | 638 void OnWindowAddedToRootWindow(aura::Window* window) override { |
| 640 if (window == view_->window_) { | 639 if (window == view_->window_) { |
| 641 window->GetHost()->AddObserver(this); | 640 window->GetHost()->AddObserver(this); |
| 642 #if defined(OS_WIN) | 641 #if defined(OS_WIN) |
| 643 if (!window->GetRootWindow()->HasObserver(this)) | 642 if (!window->GetRootWindow()->HasObserver(this)) |
| 644 window->GetRootWindow()->AddObserver(this); | 643 window->GetRootWindow()->AddObserver(this); |
| 645 #endif | 644 #endif |
| 646 } | 645 } |
| 647 } | 646 } |
| 648 | 647 |
| 649 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, | 648 void OnWindowRemovingFromRootWindow(aura::Window* window, |
| 650 aura::Window* new_root) override { | 649 aura::Window* new_root) override { |
| 651 if (window == view_->window_) { | 650 if (window == view_->window_) { |
| 652 window->GetHost()->RemoveObserver(this); | 651 window->GetHost()->RemoveObserver(this); |
| 653 #if defined(OS_WIN) | 652 #if defined(OS_WIN) |
| 654 window->GetRootWindow()->RemoveObserver(this); | 653 window->GetRootWindow()->RemoveObserver(this); |
| 655 | 654 |
| 656 const aura::Window::Windows& root_children = | 655 const aura::Window::Windows& root_children = |
| 657 window->GetRootWindow()->children(); | 656 window->GetRootWindow()->children(); |
| 658 for (size_t i = 0; i < root_children.size(); ++i) { | 657 for (size_t i = 0; i < root_children.size(); ++i) { |
| 659 if (root_children[i] != view_->window_ && | 658 if (root_children[i] != view_->window_ && |
| 660 root_children[i] != host_window_) { | 659 root_children[i] != host_window_) { |
| 661 root_children[i]->RemoveObserver(this); | 660 root_children[i]->RemoveObserver(this); |
| 662 } | 661 } |
| 663 } | 662 } |
| 664 #endif | 663 #endif |
| 665 } | 664 } |
| 666 } | 665 } |
| 667 | 666 |
| 668 // Overridden WindowTreeHostObserver: | 667 // Overridden WindowTreeHostObserver: |
| 669 virtual void OnHostMoved(const aura::WindowTreeHost* host, | 668 void OnHostMoved(const aura::WindowTreeHost* host, |
| 670 const gfx::Point& new_origin) override { | 669 const gfx::Point& new_origin) override { |
| 671 TRACE_EVENT1("ui", | 670 TRACE_EVENT1("ui", |
| 672 "WebContentsViewAura::WindowObserver::OnHostMoved", | 671 "WebContentsViewAura::WindowObserver::OnHostMoved", |
| 673 "new_origin", new_origin.ToString()); | 672 "new_origin", new_origin.ToString()); |
| 674 | 673 |
| 675 // This is for the desktop case (i.e. Aura desktop). | 674 // This is for the desktop case (i.e. Aura desktop). |
| 676 SendScreenRects(); | 675 SendScreenRects(); |
| 677 } | 676 } |
| 678 | 677 |
| 679 private: | 678 private: |
| 680 void SendScreenRects() { | 679 void SendScreenRects() { |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 if (visible) { | 1633 if (visible) { |
| 1635 if (!web_contents_->should_normally_be_visible()) | 1634 if (!web_contents_->should_normally_be_visible()) |
| 1636 web_contents_->WasShown(); | 1635 web_contents_->WasShown(); |
| 1637 } else { | 1636 } else { |
| 1638 if (web_contents_->should_normally_be_visible()) | 1637 if (web_contents_->should_normally_be_visible()) |
| 1639 web_contents_->WasHidden(); | 1638 web_contents_->WasHidden(); |
| 1640 } | 1639 } |
| 1641 } | 1640 } |
| 1642 | 1641 |
| 1643 } // namespace content | 1642 } // namespace content |
| OLD | NEW |