summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-14 16:19:08 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-14 16:19:08 +0000
commitcf1e8d3268badb311d73164664644202dbd0ef97 (patch)
treee8dc61635ced8a7ad949a6b6e62b55f387a0c41c
parent50683f6068087cc5adeba34faa9adcc9e978056a (diff)
downloadchromium_src-cf1e8d3268badb311d73164664644202dbd0ef97.zip
chromium_src-cf1e8d3268badb311d73164664644202dbd0ef97.tar.gz
chromium_src-cf1e8d3268badb311d73164664644202dbd0ef97.tar.bz2
Copies DockInfoGtk into WindowFinder.
I'm going to nuke DockInfo soonish. This is a stup in that direction. BUG=none TEST=none R=erg@chromium.org Review URL: https://codereview.chromium.org/165463003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251342 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc34
-rw-r--r--chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h11
-rw-r--r--chrome/browser/ui/gtk/tabs/window_finder.cc184
-rw-r--r--chrome/browser/ui/gtk/tabs/window_finder.h22
-rw-r--r--chrome/chrome_browser_ui.gypi2
5 files changed, 228 insertions, 25 deletions
diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
index 586dc63..21ab6d6 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
+++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.cc
@@ -17,7 +17,9 @@
#include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/browser/ui/gtk/tabs/dragged_view_gtk.h"
#include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h"
+#include "chrome/browser/ui/gtk/tabs/window_finder.h"
#include "chrome/browser/ui/media_utils.h"
+#include "chrome/browser/ui/tabs/dock_info.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "content/public/browser/notification_source.h"
@@ -362,12 +364,7 @@ void DraggedTabControllerGtk::MoveDetached(const gfx::Point& screen_point) {
TabStripGtk* DraggedTabControllerGtk::GetTabStripForPoint(
const gfx::Point& screen_point) {
- GtkWidget* dragged_window = dragged_view_->widget();
- dock_windows_.insert(dragged_window);
- gfx::NativeWindow local_window =
- DockInfo::GetLocalProcessWindowAtPoint(
- chrome::HOST_DESKTOP_TYPE_NATIVE, screen_point, dock_windows_);
- dock_windows_.erase(dragged_window);
+ gfx::NativeWindow local_window = GetLocalProcessWindow(screen_point);
if (!local_window)
return NULL;
@@ -778,7 +775,7 @@ bool DraggedTabControllerGtk::CompleteDrag() {
Browser* new_browser =
source_tabstrip_->model()->delegate()->CreateNewStripWithContents(
- contentses, window_bounds, dock_info_, window->IsMaximized());
+ contentses, window_bounds, DockInfo(), window->IsMaximized());
RestoreSelection(new_browser->tab_strip_model());
new_browser->window()->Show();
CleanUpHiddenFrame();
@@ -874,17 +871,8 @@ void DraggedTabControllerGtk::OnAnimateToBoundsComplete() {
void DraggedTabControllerGtk::BringWindowUnderMouseToFront() {
// If we're going to dock to another window, bring it to the front.
- gfx::NativeWindow window = dock_info_.window();
- if (!window) {
- gfx::NativeView dragged_tab = dragged_view_->widget();
- dock_windows_.insert(dragged_tab);
- window = DockInfo::GetLocalProcessWindowAtPoint(
- chrome::HOST_DESKTOP_TYPE_NATIVE,
- gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(),
- dock_windows_);
- dock_windows_.erase(dragged_tab);
- }
-
+ gfx::NativeWindow window = GetLocalProcessWindow(
+ gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
if (window)
gtk_window_present(GTK_WINDOW(window));
}
@@ -898,3 +886,13 @@ bool DraggedTabControllerGtk::AreTabsConsecutive() {
}
return true;
}
+
+gfx::NativeWindow DraggedTabControllerGtk::GetLocalProcessWindow(
+ const gfx::Point& screen_point) {
+ std::set<GtkWidget*> dragged_window;
+ dragged_window.insert(dragged_view_->widget());
+ return GetLocalProcessWindowAtPoint(
+ gfx::Screen::GetNativeScreen()->GetCursorScreenPoint(),
+ dragged_window);
+
+}
diff --git a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
index a2a384a..487eed19 100644
--- a/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
+++ b/chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h
@@ -15,7 +15,6 @@
#include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h"
#include "chrome/browser/ui/gtk/tabs/drag_data.h"
-#include "chrome/browser/ui/tabs/dock_info.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_delegate.h"
@@ -217,6 +216,10 @@ class DraggedTabControllerGtk : public content::NotificationObserver,
// |source_tabstrip_|.
bool AreTabsConsecutive();
+ // Returns the NativeWindow at the specified point, not including the window
+ // being dragged.
+ gfx::NativeWindow GetLocalProcessWindow(const gfx::Point& screen_point);
+
// Handles registering for notifications.
content::NotificationRegistrar registrar_;
@@ -255,12 +258,6 @@ class DraggedTabControllerGtk : public content::NotificationObserver,
// True until |MoveAttached| is invoked once.
bool initial_move_;
- // DockInfo for the tabstrip.
- DockInfo dock_info_;
-
- typedef std::set<GtkWidget*> DockWindows;
- DockWindows dock_windows_;
-
// Timer used to bring the window under the cursor to front. If the user
// stops moving the mouse for a brief time over a browser window, it is
// brought to front.
diff --git a/chrome/browser/ui/gtk/tabs/window_finder.cc b/chrome/browser/ui/gtk/tabs/window_finder.cc
new file mode 100644
index 0000000..e6e5afc
--- /dev/null
+++ b/chrome/browser/ui/gtk/tabs/window_finder.cc
@@ -0,0 +1,184 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/gtk/tabs/window_finder.h"
+
+#include <gtk/gtk.h>
+
+#include "base/logging.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/gtk/browser_window_gtk.h"
+#include "chrome/browser/ui/gtk/gtk_util.h"
+#include "chrome/browser/ui/gtk/tabs/tab_gtk.h"
+#include "chrome/browser/ui/host_desktop.h"
+#include "ui/base/x/x11_util.h"
+#include "ui/gfx/native_widget_types.h"
+
+namespace {
+
+////////////////////////////////////////////////////////////////////////////////
+// BaseWindowFinder
+//
+// Base class used to locate a window. A subclass need only override
+// ShouldStopIterating to determine when iteration should stop.
+class BaseWindowFinder : public ui::EnumerateWindowsDelegate {
+ public:
+ explicit BaseWindowFinder(const std::set<GtkWidget*>& ignore) {
+ std::set<GtkWidget*>::iterator iter;
+ for (iter = ignore.begin(); iter != ignore.end(); iter++) {
+ XID xid = ui::GetX11WindowFromGtkWidget(*iter);
+ ignore_.insert(xid);
+ }
+ }
+
+ virtual ~BaseWindowFinder() {}
+
+ protected:
+ // Returns true if |window| is in the ignore list.
+ bool ShouldIgnoreWindow(XID window) {
+ return (ignore_.find(window) != ignore_.end());
+ }
+
+ // Returns true if iteration should stop, false otherwise.
+ virtual bool ShouldStopIterating(XID window) OVERRIDE {
+ return false;
+ }
+
+ private:
+ std::set<XID> ignore_;
+
+ DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// TopMostFinder
+//
+// Helper class to determine if a particular point of a window is not obscured
+// by another window.
+class TopMostFinder : public BaseWindowFinder {
+ public:
+ // Returns true if |window| is not obscured by another window at the
+ // location |screen_loc|, not including the windows in |ignore|.
+ static bool IsTopMostWindowAtPoint(XID window,
+ const gfx::Point& screen_loc,
+ const std::set<GtkWidget*>& ignore) {
+ TopMostFinder finder(window, screen_loc, ignore);
+ return finder.is_top_most_;
+ }
+
+ protected:
+ virtual bool ShouldStopIterating(XID window) OVERRIDE {
+ if (BaseWindowFinder::ShouldIgnoreWindow(window))
+ return false;
+
+ if (window == target_) {
+ // Window is topmost, stop iterating.
+ is_top_most_ = true;
+ return true;
+ }
+
+ if (!ui::IsWindowVisible(window)) {
+ // The window isn't visible, keep iterating.
+ return false;
+ }
+
+ if (ui::WindowContainsPoint(window, screen_loc_))
+ return true;
+
+ return false;
+ }
+
+ private:
+ TopMostFinder(XID window,
+ const gfx::Point& screen_loc,
+ const std::set<GtkWidget*>& ignore)
+ : BaseWindowFinder(ignore),
+ target_(window),
+ screen_loc_(screen_loc),
+ is_top_most_(false) {
+ ui::EnumerateTopLevelWindows(this);
+ }
+
+ // The window we're looking for.
+ XID target_;
+
+ // Location of window to find.
+ gfx::Point screen_loc_;
+
+ // Is target_ the top most window? This is initially false but set to true
+ // in ShouldStopIterating if target_ is passed in.
+ bool is_top_most_;
+
+ DISALLOW_COPY_AND_ASSIGN(TopMostFinder);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// LocalProcessWindowFinder
+//
+// Helper class to determine if a particular point of a window from our process
+// is not obscured by another window.
+class LocalProcessWindowFinder : public BaseWindowFinder {
+ public:
+ // Returns the XID from our process at screen_loc that is not obscured by
+ // another window. Returns 0 otherwise.
+ static XID GetProcessWindowAtPoint(const gfx::Point& screen_loc,
+ const std::set<GtkWidget*>& ignore) {
+ LocalProcessWindowFinder finder(screen_loc, ignore);
+ if (finder.result_ &&
+ TopMostFinder::IsTopMostWindowAtPoint(finder.result_, screen_loc,
+ ignore)) {
+ return finder.result_;
+ }
+ return 0;
+ }
+
+ protected:
+ virtual bool ShouldStopIterating(XID window) OVERRIDE {
+ if (BaseWindowFinder::ShouldIgnoreWindow(window))
+ return false;
+
+ // Check if this window is in our process.
+ if (!BrowserWindowGtk::GetBrowserWindowForXID(window))
+ return false;
+
+ if (!ui::IsWindowVisible(window))
+ return false;
+
+ if (ui::WindowContainsPoint(window, screen_loc_)) {
+ result_ = window;
+ return true;
+ }
+
+ return false;
+ }
+
+ private:
+ LocalProcessWindowFinder(const gfx::Point& screen_loc,
+ const std::set<GtkWidget*>& ignore)
+ : BaseWindowFinder(ignore),
+ screen_loc_(screen_loc),
+ result_(0) {
+ ui::EnumerateTopLevelWindows(this);
+ }
+
+ // Position of the mouse.
+ gfx::Point screen_loc_;
+
+ // The resulting window. This is initially null but set to true in
+ // ShouldStopIterating if an appropriate window is found.
+ XID result_;
+
+ DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder);
+};
+
+} // namespace
+
+GtkWindow* GetLocalProcessWindowAtPoint(
+ const gfx::Point& screen_point,
+ const std::set<GtkWidget*>& ignore) {
+ XID xid =
+ LocalProcessWindowFinder::GetProcessWindowAtPoint(screen_point, ignore);
+ return BrowserWindowGtk::GetBrowserWindowForXID(xid);
+}
diff --git a/chrome/browser/ui/gtk/tabs/window_finder.h b/chrome/browser/ui/gtk/tabs/window_finder.h
new file mode 100644
index 0000000..1fdf1c7
--- /dev/null
+++ b/chrome/browser/ui/gtk/tabs/window_finder.h
@@ -0,0 +1,22 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_GTK_TABS_WINDOW_FINDER_H_
+#define CHROME_BROWSER_UI_GTK_TABS_WINDOW_FINDER_H_
+
+#include <set>
+
+typedef struct _GtkWidget GtkWidget;
+typedef struct _GtkWindow GtkWindow;
+
+namespace gfx {
+class Point;
+}
+
+// Returns the Window at the specified point, ignoring the windows in |ignore|.
+GtkWindow* GetLocalProcessWindowAtPoint(
+ const gfx::Point& screen_point,
+ const std::set<GtkWidget*>& ignore);
+
+#endif // CHROME_BROWSER_UI_GTK_TABS_WINDOW_FINDER_H_
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 9408442..c78aa1c 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -1408,6 +1408,8 @@
'browser/ui/gtk/tabs/tab_strip_gtk.h',
'browser/ui/gtk/tabs/tab_strip_menu_controller.cc',
'browser/ui/gtk/tabs/tab_strip_menu_controller.h',
+ 'browser/ui/gtk/tabs/window_finder.cc',
+ 'browser/ui/gtk/tabs/window_finder.h',
'browser/ui/gtk/task_manager_gtk.cc',
'browser/ui/gtk/task_manager_gtk.h',
'browser/ui/gtk/throbber_gtk.cc',