This source file includes following definitions.
- ShouldIgnoreWindow
- ShouldStopIterating
- IsTopMostWindowAtPoint
- ShouldStopIterating
- is_top_most_
- GetProcessWindowAtPoint
- ShouldStopIterating
- result_
- GetLocalProcessWindowAtPoint
#include "chrome/browser/ui/views/tabs/window_finder.h"
#include "base/debug/trace_event.h"
#include "chrome/browser/ui/host_desktop.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/x/x11_util.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#if defined(USE_ASH)
aura::Window* GetLocalProcessWindowAtPointAsh(
const gfx::Point& screen_point,
const std::set<aura::Window*>& ignore);
#endif
namespace {
class BaseWindowFinder : public ui::EnumerateWindowsDelegate {
public:
explicit BaseWindowFinder(const std::set<aura::Window*>& ignore) {
std::set<aura::Window*>::iterator iter;
for (iter = ignore.begin(); iter != ignore.end(); iter++) {
XID xid = (*iter)->GetHost()->GetAcceleratedWidget();
ignore_.insert(xid);
}
}
virtual ~BaseWindowFinder() {}
protected:
bool ShouldIgnoreWindow(XID window) {
return (ignore_.find(window) != ignore_.end());
}
virtual bool ShouldStopIterating(XID window) OVERRIDE {
return false;
}
private:
std::set<XID> ignore_;
DISALLOW_COPY_AND_ASSIGN(BaseWindowFinder);
};
class TopMostFinder : public BaseWindowFinder {
public:
static bool IsTopMostWindowAtPoint(XID window,
const gfx::Point& screen_loc,
const std::set<aura::Window*>& 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_) {
is_top_most_ = true;
return true;
}
if (!ui::IsWindowVisible(window)) {
return false;
}
return ui::WindowContainsPoint(window, screen_loc_);
}
private:
TopMostFinder(XID window,
const gfx::Point& screen_loc,
const std::set<aura::Window*>& ignore)
: BaseWindowFinder(ignore),
target_(window),
screen_loc_(screen_loc),
is_top_most_(false) {
ui::EnumerateTopLevelWindows(this);
}
XID target_;
gfx::Point screen_loc_;
bool is_top_most_;
DISALLOW_COPY_AND_ASSIGN(TopMostFinder);
};
class LocalProcessWindowFinder : public BaseWindowFinder {
public:
static XID GetProcessWindowAtPoint(const gfx::Point& screen_loc,
const std::set<aura::Window*>& 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;
if (!aura::WindowTreeHost::GetForAcceleratedWidget(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<aura::Window*>& ignore)
: BaseWindowFinder(ignore),
screen_loc_(screen_loc),
result_(0) {
ui::EnumerateTopLevelWindows(this);
}
gfx::Point screen_loc_;
XID result_;
DISALLOW_COPY_AND_ASSIGN(LocalProcessWindowFinder);
};
}
aura::Window* GetLocalProcessWindowAtPoint(
chrome::HostDesktopType host_desktop_type,
const gfx::Point& screen_point,
const std::set<aura::Window*>& ignore) {
#if defined(USE_ASH)
if (host_desktop_type == chrome::HOST_DESKTOP_TYPE_ASH)
return GetLocalProcessWindowAtPointAsh(screen_point, ignore);
#endif
XID xid =
LocalProcessWindowFinder::GetProcessWindowAtPoint(screen_point, ignore);
return views::DesktopWindowTreeHostX11::GetContentWindowForXID(xid);
}