1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/controls/resize_area.h"
#include "base/i18n/rtl.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/resize_area_delegate.h"
namespace views {
ResizeArea::ResizeArea(ResizeAreaDelegate* delegate) : delegate_(delegate) {
GetViewAccessibility().SetRole(ax::mojom::Role::kSplitter);
}
ResizeArea::~ResizeArea() = default;
ui::Cursor ResizeArea::GetCursor(const ui::MouseEvent& event) {
return GetEnabled() ? ui::Cursor(ui::mojom::CursorType::kEastWestResize)
: ui::Cursor();
}
void ResizeArea::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::EventType::kGestureTapDown) {
SetInitialPosition(event->x());
event->SetHandled();
} else if (event->type() == ui::EventType::kGestureScrollBegin ||
event->type() == ui::EventType::kGestureScrollUpdate) {
ReportResizeAmount(event->x(), false);
event->SetHandled();
} else if (event->type() == ui::EventType::kGestureEnd) {
if (is_resizing_) {
ReportResizeAmount(event->x(), true);
}
event->SetHandled();
}
}
bool ResizeArea::OnMousePressed(const ui::MouseEvent& event) {
if (!event.IsOnlyLeftMouseButton()) {
return false;
}
SetInitialPosition(event.x());
return true;
}
bool ResizeArea::OnMouseDragged(const ui::MouseEvent& event) {
if (!event.IsLeftMouseButton()) {
return false;
}
ReportResizeAmount(event.x(), false);
return true;
}
void ResizeArea::OnMouseReleased(const ui::MouseEvent& event) {
if (is_resizing_) {
ReportResizeAmount(event.x(), true);
}
}
void ResizeArea::OnMouseCaptureLost() {
ReportResizeAmount(initial_position_, true);
}
void ResizeArea::ReportResizeAmount(int resize_amount, bool last_update) {
gfx::Point point(resize_amount, 0);
View::ConvertPointToScreen(this, &point);
resize_amount = point.x() - initial_position_;
is_resizing_ = !last_update;
delegate_->OnResize(base::i18n::IsRTL() ? -resize_amount : resize_amount,
last_update);
}
void ResizeArea::SetInitialPosition(int event_x) {
gfx::Point point(event_x, 0);
View::ConvertPointToScreen(this, &point);
initial_position_ = point.x();
}
BEGIN_METADATA(ResizeArea)
END_METADATA
} // namespace views
|