Commit cf1e8d32 authored by sky@chromium.org's avatar sky@chromium.org

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
parent 50683f60
...@@ -17,7 +17,9 @@ ...@@ -17,7 +17,9 @@
#include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/browser/ui/gtk/gtk_util.h"
#include "chrome/browser/ui/gtk/tabs/dragged_view_gtk.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/tab_strip_gtk.h"
#include "chrome/browser/ui/gtk/tabs/window_finder.h"
#include "chrome/browser/ui/media_utils.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.h"
#include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
...@@ -362,12 +364,7 @@ void DraggedTabControllerGtk::MoveDetached(const gfx::Point& screen_point) { ...@@ -362,12 +364,7 @@ void DraggedTabControllerGtk::MoveDetached(const gfx::Point& screen_point) {
TabStripGtk* DraggedTabControllerGtk::GetTabStripForPoint( TabStripGtk* DraggedTabControllerGtk::GetTabStripForPoint(
const gfx::Point& screen_point) { const gfx::Point& screen_point) {
GtkWidget* dragged_window = dragged_view_->widget(); gfx::NativeWindow local_window = GetLocalProcessWindow(screen_point);
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);
if (!local_window) if (!local_window)
return NULL; return NULL;
...@@ -778,7 +775,7 @@ bool DraggedTabControllerGtk::CompleteDrag() { ...@@ -778,7 +775,7 @@ bool DraggedTabControllerGtk::CompleteDrag() {
Browser* new_browser = Browser* new_browser =
source_tabstrip_->model()->delegate()->CreateNewStripWithContents( source_tabstrip_->model()->delegate()->CreateNewStripWithContents(
contentses, window_bounds, dock_info_, window->IsMaximized()); contentses, window_bounds, DockInfo(), window->IsMaximized());
RestoreSelection(new_browser->tab_strip_model()); RestoreSelection(new_browser->tab_strip_model());
new_browser->window()->Show(); new_browser->window()->Show();
CleanUpHiddenFrame(); CleanUpHiddenFrame();
...@@ -874,17 +871,8 @@ void DraggedTabControllerGtk::OnAnimateToBoundsComplete() { ...@@ -874,17 +871,8 @@ void DraggedTabControllerGtk::OnAnimateToBoundsComplete() {
void DraggedTabControllerGtk::BringWindowUnderMouseToFront() { void DraggedTabControllerGtk::BringWindowUnderMouseToFront() {
// If we're going to dock to another window, bring it to the front. // If we're going to dock to another window, bring it to the front.
gfx::NativeWindow window = dock_info_.window(); gfx::NativeWindow window = GetLocalProcessWindow(
if (!window) { gfx::Screen::GetNativeScreen()->GetCursorScreenPoint());
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);
}
if (window) if (window)
gtk_window_present(GTK_WINDOW(window)); gtk_window_present(GTK_WINDOW(window));
} }
...@@ -898,3 +886,13 @@ bool DraggedTabControllerGtk::AreTabsConsecutive() { ...@@ -898,3 +886,13 @@ bool DraggedTabControllerGtk::AreTabsConsecutive() {
} }
return true; 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);
}
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/ui/gtk/tabs/drag_data.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_observer.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
...@@ -217,6 +216,10 @@ class DraggedTabControllerGtk : public content::NotificationObserver, ...@@ -217,6 +216,10 @@ class DraggedTabControllerGtk : public content::NotificationObserver,
// |source_tabstrip_|. // |source_tabstrip_|.
bool AreTabsConsecutive(); 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. // Handles registering for notifications.
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
...@@ -255,12 +258,6 @@ class DraggedTabControllerGtk : public content::NotificationObserver, ...@@ -255,12 +258,6 @@ class DraggedTabControllerGtk : public content::NotificationObserver,
// True until |MoveAttached| is invoked once. // True until |MoveAttached| is invoked once.
bool initial_move_; 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 // 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 // stops moving the mouse for a brief time over a browser window, it is
// brought to front. // brought to front.
......
// 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);
}
// 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_
...@@ -1408,6 +1408,8 @@ ...@@ -1408,6 +1408,8 @@
'browser/ui/gtk/tabs/tab_strip_gtk.h', '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.cc',
'browser/ui/gtk/tabs/tab_strip_menu_controller.h', '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.cc',
'browser/ui/gtk/task_manager_gtk.h', 'browser/ui/gtk/task_manager_gtk.h',
'browser/ui/gtk/throbber_gtk.cc', 'browser/ui/gtk/throbber_gtk.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment