Commit bb7db6ba authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Maximize window vertically or horizontally when the maximize button is middle...

Maximize window vertically or horizontally when the maximize button is middle or right clicked on Linux respectively.

BUG=362546
TEST=Manual, see bug

Review URL: https://codereview.chromium.org/288203005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271812 0039d316-1c4b-4281-b951-d872f2087c98
parent 87431267
...@@ -16,10 +16,13 @@ ...@@ -16,10 +16,13 @@
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/events/event.h" #include "ui/events/event.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
#include "ui/views/linux_ui/linux_ui.h" #include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
#include "ui/views/widget/native_widget_aura.h" #include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/widget.h"
namespace { namespace {
...@@ -96,9 +99,6 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) { ...@@ -96,9 +99,6 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) {
if (event->type() != ui::ET_MOUSE_PRESSED) if (event->type() != ui::ET_MOUSE_PRESSED)
return; return;
if (!(event->IsLeftMouseButton() || event->IsMiddleMouseButton()))
return;
aura::Window* target = static_cast<aura::Window*>(event->target()); aura::Window* target = static_cast<aura::Window*>(event->target());
if (!target->delegate()) if (!target->delegate())
return; return;
...@@ -110,10 +110,29 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) { ...@@ -110,10 +110,29 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) {
previous_click_component = click_component_; previous_click_component = click_component_;
click_component_ = component; click_component_ = component;
} }
if (component == HTCLIENT)
return;
if (event->IsMiddleMouseButton() && (component == HTCAPTION)) { if (component == HTCAPTION) {
OnClickedCaption(event, previous_click_component);
} else if (component == HTMAXBUTTON) {
OnClickedMaximizeButton(event);
} else {
// Get the |x_root_window_| location out of the native event.
if (event->IsLeftMouseButton() && event->native_event()) {
const gfx::Point x_root_location =
ui::EventSystemLocationFromNative(event->native_event());
if (target->GetProperty(aura::client::kCanResizeKey) &&
DispatchHostWindowDragMovement(component, x_root_location)) {
event->StopPropagation();
}
}
}
}
void X11WindowEventFilter::OnClickedCaption(ui::MouseEvent* event,
int previous_click_component) {
aura::Window* target = static_cast<aura::Window*>(event->target());
if (event->IsMiddleMouseButton()) {
LinuxUI::NonClientMiddleClickAction action = LinuxUI::NonClientMiddleClickAction action =
LinuxUI::MIDDLE_CLICK_ACTION_LOWER; LinuxUI::MIDDLE_CLICK_ACTION_LOWER;
LinuxUI* linux_ui = LinuxUI::instance(); LinuxUI* linux_ui = LinuxUI::instance();
...@@ -139,12 +158,10 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) { ...@@ -139,12 +158,10 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) {
return; return;
} }
// Left button case. if (event->IsLeftMouseButton() && event->flags() & ui::EF_IS_DOUBLE_CLICK) {
if (event->flags() & ui::EF_IS_DOUBLE_CLICK) {
click_component_ = HTNOWHERE; click_component_ = HTNOWHERE;
if (component == HTCAPTION && if (target->GetProperty(aura::client::kCanMaximizeKey) &&
target->GetProperty(aura::client::kCanMaximizeKey) && previous_click_component == HTCAPTION) {
previous_click_component == component) {
// Our event is a double click in the caption area in a window that can be // Our event is a double click in the caption area in a window that can be
// maximized. We are responsible for dispatching this as a minimize/ // maximized. We are responsible for dispatching this as a minimize/
// maximize on X11 (Windows converts this to min/max events for us). // maximize on X11 (Windows converts this to min/max events for us).
...@@ -155,14 +172,34 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) { ...@@ -155,14 +172,34 @@ void X11WindowEventFilter::OnMouseEvent(ui::MouseEvent* event) {
} }
// Get the |x_root_window_| location out of the native event. // Get the |x_root_window_| location out of the native event.
if (event->native_event()) { if (event->IsLeftMouseButton() && event->native_event()) {
const gfx::Point x_root_location = const gfx::Point x_root_location =
ui::EventSystemLocationFromNative(event->native_event()); ui::EventSystemLocationFromNative(event->native_event());
if ((component == HTCAPTION || if (DispatchHostWindowDragMovement(HTCAPTION, x_root_location))
target->GetProperty(aura::client::kCanResizeKey)) &&
DispatchHostWindowDragMovement(component, x_root_location)) {
event->StopPropagation(); event->StopPropagation();
} }
}
void X11WindowEventFilter::OnClickedMaximizeButton(ui::MouseEvent* event) {
aura::Window* target = static_cast<aura::Window*>(event->target());
views::Widget* widget = views::Widget::GetWidgetForNativeView(target);
if (!widget)
return;
gfx::Screen* screen = gfx::Screen::GetNativeScreen();
gfx::Rect display_work_area =
screen->GetDisplayNearestWindow(target).work_area();
gfx::Rect bounds = widget->GetWindowBoundsInScreen();
if (event->IsMiddleMouseButton()) {
bounds.set_y(display_work_area.y());
bounds.set_height(display_work_area.height());
widget->SetBounds(bounds);
event->StopPropagation();
} else if (event->IsRightMouseButton()) {
bounds.set_x(display_work_area.x());
bounds.set_width(display_work_area.width());
widget->SetBounds(bounds);
event->StopPropagation();
} }
} }
......
...@@ -39,6 +39,13 @@ class VIEWS_EXPORT X11WindowEventFilter : public ui::EventHandler { ...@@ -39,6 +39,13 @@ class VIEWS_EXPORT X11WindowEventFilter : public ui::EventHandler {
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
private: private:
// Called when the user clicked the caption area.
void OnClickedCaption(ui::MouseEvent* event,
int previous_click_component);
// Called when the user clicked the maximize button.
void OnClickedMaximizeButton(ui::MouseEvent* event);
void ToggleMaximizedState(); void ToggleMaximizedState();
// Dispatches a _NET_WM_MOVERESIZE message to the window manager to tell it // Dispatches a _NET_WM_MOVERESIZE message to the window manager to tell it
......
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