#include "ash/ash_constants.h"
#include "ash/wm/header_painter.h"
-#include "ash/wm/window_state.h"
+#include "ash/wm/resize_handle_window_targeter.h"
#include "ash/wm/window_state_observer.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
namespace ash {
-namespace {
-
-// To allow easy resize, the resize handles should slightly overlap the content
-// area of non-maximized and non-fullscreen windows.
-class ResizeHandleWindowTargeter : public wm::WindowStateObserver,
- public aura::WindowObserver,
- public aura::WindowTargeter {
- public:
- explicit ResizeHandleWindowTargeter(aura::Window* window)
- : window_(window) {
- wm::WindowState* window_state = wm::GetWindowState(window_);
- OnWindowShowTypeChanged(window_state, wm::SHOW_TYPE_DEFAULT);
- window_state->AddObserver(this);
- window_->AddObserver(this);
- }
-
- virtual ~ResizeHandleWindowTargeter() {
- if (window_) {
- window_->RemoveObserver(this);
- wm::GetWindowState(window_)->RemoveObserver(this);
- }
- }
-
- private:
- // wm::WindowStateObserver:
- virtual void OnWindowShowTypeChanged(wm::WindowState* window_state,
- wm::WindowShowType old_type) OVERRIDE {
- if (window_state->IsMaximizedOrFullscreen()) {
- frame_border_inset_ = gfx::Insets();
- } else {
- frame_border_inset_ = gfx::Insets(kResizeInsideBoundsSize,
- kResizeInsideBoundsSize,
- kResizeInsideBoundsSize,
- kResizeInsideBoundsSize);
- }
- }
-
- // aura::WindowObserver:
- virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
- CHECK_EQ(window_, window);
- wm::GetWindowState(window_)->RemoveObserver(this);
- window_ = NULL;
- }
-
- // aura::WindowTargeter:
- virtual ui::EventTarget* FindTargetForLocatedEvent(
- ui::EventTarget* root,
- ui::LocatedEvent* event) OVERRIDE {
- // If the event falls very close to the inside of the frame border, then
- // target the window itself, so that the window can be resized easily.
- aura::Window* window = static_cast<aura::Window*>(root);
- if (window == window_ && !frame_border_inset_.empty()) {
- gfx::Rect bounds = gfx::Rect(window_->bounds().size());
- bounds.Inset(frame_border_inset_);
- if (!bounds.Contains(event->location()))
- return window_;
- }
- return aura::WindowTargeter::FindTargetForLocatedEvent(root, event);
- }
-
- virtual bool SubtreeShouldBeExploredForEvent(
- ui::EventTarget* target,
- const ui::LocatedEvent& event) OVERRIDE {
- if (target == window_) {
- // Defer to the parent's targeter on whether |window_| should be able to
- // receive the event.
- ui::EventTarget* parent = target->GetParentTarget();
- if (parent) {
- ui::EventTargeter* targeter = parent->GetEventTargeter();
- if (targeter)
- return targeter->SubtreeShouldBeExploredForEvent(target, event);
- }
- }
- return aura::WindowTargeter::SubtreeShouldBeExploredForEvent(target, event);
- }
-
- aura::Window* window_;
- gfx::Insets frame_border_inset_;
-
- DISALLOW_COPY_AND_ASSIGN(ResizeHandleWindowTargeter);
-};
-
-} // namespace
-
FrameBorderHitTestController::FrameBorderHitTestController(views::Widget* frame)
: frame_window_(frame->GetNativeWindow()) {
- gfx::Insets mouse_outer_insets(-kResizeOutsideBoundsSize,
- -kResizeOutsideBoundsSize,
- -kResizeOutsideBoundsSize,
- -kResizeOutsideBoundsSize);
- gfx::Insets touch_outer_insets = mouse_outer_insets.Scale(
- kResizeOutsideBoundsScaleForTouch);
- // Ensure we get resize cursors for a few pixels outside our bounds.
- frame_window_->SetHitTestBoundsOverrideOuter(mouse_outer_insets,
- touch_outer_insets);
-
- frame_window_->set_event_targeter(scoped_ptr<ui::EventTargeter>(
- new ResizeHandleWindowTargeter(frame_window_)));
+ frame_window_->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
+ new ResizeHandleWindowTargeter(frame_window_, NULL)));
}
FrameBorderHitTestController::~FrameBorderHitTestController() {