chromium/ui/views/touchui/touch_selection_controller_impl.cc

// Copyright 2018 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/touchui/touch_selection_controller_impl.h"

#include <set>
#include <utility>

#include "base/check_op.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/notreached.h"
#include "base/time/time.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_targeter.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_features.h"
#include "ui/color/color_id.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/touch_selection/touch_selection_magnifier_aura.h"
#include "ui/touch_selection/touch_selection_metrics.h"
#include "ui/touch_selection/vector_icons/vector_icons.h"
#include "ui/views/view_utils.h"
#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/wm/core/coordinate_conversion.h"

namespace {

// Constants defining the visual attributes of selection handles

// When a handle is dragged, the drag position reported to the client view is
// offset vertically to represent the cursor position. This constant specifies
// the offset in pixels above the bottom of the selection (see pic below). This
// is required because say if this is zero, that means the drag position we
// report is right on the text baseline. In that case, a vertical movement of
// even one pixel will make the handle jump to the line below it. So when the
// user just starts dragging, the handle will jump to the next line if the user
// makes any vertical movement. So we have this non-zero offset to prevent this
// jumping.
//
// Editing handle widget showing the padding and difference between the position
// of the EventType::kGestureScrollUpdate event and the drag position reported
// to the client:
//                            ___________
//    Selection Highlight --->_____|__|<-|---- Drag position reported to client
//                              _  |  O  |
//            Bottom Padding __|   |   <-|---- EventType::kGestureScrollUpdate
//            position
//                             |_  |_____|<--- Editing handle widget
//
//                                 | |
//                                  T
//                          Horizontal Padding
//
constexpr int kSelectionHandleVerticalDragOffset =;

// Minimum height for selection handle bar. If the bar height is going to be
// less than this value, handle will not be shown.
constexpr int kSelectionHandleBarMinHeight =;
// Maximum amount that selection handle bar can stick out of client view's
// boundaries.
constexpr int kSelectionHandleBarBottomAllowance =;

// Opacity of the selection handle image.
constexpr float kSelectionHandleOpacity =;

// Delay before showing the quick menu after it is requested, in milliseconds.
constexpr int kQuickMenuDelayInMs =;

// Vertical offset to apply from the bottom of the selection/text baseline to
// the top of the handle image.
constexpr int kSelectionHandleVerticalOffset =;
int GetSelectionHandleVerticalOffset() {}

// Padding to apply horizontally around and vertically below the handle image.
// This is included in the touch handle target area to make dragging the handle
// easier (see pic above).
constexpr int kSelectionHandleHorizontalPadding =;
constexpr int kSelectionHandleBottomPadding =;
constexpr int kSelectionHandlePadding =;
int GetSelectionHandleHorizontalPadding() {}
int GetSelectionHandleBottomPadding() {}

gfx::Image* GetCenterHandleImage() {}

gfx::Image* GetLeftHandleImage() {}

gfx::Image* GetRightHandleImage() {}

// Return the appropriate handle image based on the bound's type
gfx::Image* GetHandleImage(gfx::SelectionBound::Type bound_type) {}

// Returns the appropriate handle vector icon based on the handle bound type.
ui::ImageModel GetHandleVectorIcon(gfx::SelectionBound::Type bound_type) {}

// Returns the appropriate handle image model based on the handle bound type.
ui::ImageModel GetHandleImageModel(gfx::SelectionBound::Type bound_type) {}

// Calculates the bounds of the widget containing the selection handle based
// on the SelectionBound's type and location.
gfx::Rect GetSelectionWidgetBounds(const gfx::SelectionBound& bound) {}

gfx::Size GetMaxHandleImageSize() {}

// Convenience methods to convert a |bound| from screen to the |client|'s
// coordinate system and vice versa.
// Note that this is not quite correct because it does not take into account
// transforms such as rotation and scaling. This should be in TouchEditable.
// TODO(varunjain): Fix this.
gfx::SelectionBound ConvertFromScreen(ui::TouchEditable* client,
                                      const gfx::SelectionBound& bound) {}

gfx::SelectionBound ConvertToScreen(ui::TouchEditable* client,
                                    const gfx::SelectionBound& bound) {}

gfx::Rect BoundToRect(const gfx::SelectionBound& bound) {}

std::unique_ptr<views::Widget> CreateHandleWidget(gfx::NativeView parent) {}

}  // namespace

namespace views {

EditingHandleView;

// A View that displays the text selection handle.
class TouchSelectionControllerImpl::EditingHandleView : public View {};

BEGIN_METADATA()

TouchSelectionControllerImpl::TouchSelectionControllerImpl(
    ui::TouchEditable* client_view)
    :{}

TouchSelectionControllerImpl::~TouchSelectionControllerImpl() {}

void TouchSelectionControllerImpl::SelectionChanged() {}

void TouchSelectionControllerImpl::ToggleQuickMenu() {}

void TouchSelectionControllerImpl::ShowQuickMenuImmediatelyForTesting() {}

void TouchSelectionControllerImpl::OnDragBegin(EditingHandleView* handle) {}

void TouchSelectionControllerImpl::OnDragUpdate(EditingHandleView* handle,
                                                const gfx::Point& drag_pos) {}

void TouchSelectionControllerImpl::OnDragEnd() {}

void TouchSelectionControllerImpl::ConvertPointToClientView(
    EditingHandleView* source,
    gfx::Point* point) {}

void TouchSelectionControllerImpl::SetHandleBound(
    EditingHandleView* handle,
    const gfx::SelectionBound& bound,
    const gfx::SelectionBound& bound_in_screen) {}

bool TouchSelectionControllerImpl::ShouldShowHandleFor(
    const gfx::SelectionBound& bound) const {}

bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const {}

void TouchSelectionControllerImpl::ExecuteCommand(int command_id,
                                                  int event_flags) {}

void TouchSelectionControllerImpl::RunContextMenu() {}

bool TouchSelectionControllerImpl::ShouldShowQuickMenu() {}

std::u16string TouchSelectionControllerImpl::GetSelectedText() {}

void TouchSelectionControllerImpl::OnWidgetDestroying(Widget* widget) {}

void TouchSelectionControllerImpl::OnWidgetBoundsChanged(
    Widget* widget,
    const gfx::Rect& new_bounds) {}

void TouchSelectionControllerImpl::OnEvent(const ui::Event& event) {}

void TouchSelectionControllerImpl::QuickMenuTimerFired() {}

void TouchSelectionControllerImpl::StartQuickMenuTimer() {}

void TouchSelectionControllerImpl::UpdateQuickMenu() {}

void TouchSelectionControllerImpl::HideQuickMenu() {}

gfx::Rect TouchSelectionControllerImpl::GetQuickMenuAnchorRect() const {}

void TouchSelectionControllerImpl::ShowMagnifier(
    const gfx::SelectionBound& focus_bound_in_screen) {}

void TouchSelectionControllerImpl::HideMagnifier() {}

void TouchSelectionControllerImpl::CreateHandleWidgets() {}

EditingHandleView* TouchSelectionControllerImpl::GetSelectionHandle1() {}

EditingHandleView* TouchSelectionControllerImpl::GetSelectionHandle2() {}

EditingHandleView* TouchSelectionControllerImpl::GetCursorHandle() {}

EditingHandleView* TouchSelectionControllerImpl::GetDraggingHandle() {}

gfx::NativeView TouchSelectionControllerImpl::GetCursorHandleNativeView() {}

gfx::SelectionBound::Type
TouchSelectionControllerImpl::GetSelectionHandle1Type() {}

gfx::Rect TouchSelectionControllerImpl::GetSelectionHandle1Bounds() {}

gfx::Rect TouchSelectionControllerImpl::GetSelectionHandle2Bounds() {}

gfx::Rect TouchSelectionControllerImpl::GetCursorHandleBounds() {}

bool TouchSelectionControllerImpl::IsSelectionHandle1Visible() {}

bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() {}

bool TouchSelectionControllerImpl::IsCursorHandleVisible() {}

gfx::Rect TouchSelectionControllerImpl::GetExpectedHandleBounds(
    const gfx::SelectionBound& bound) {}

View* TouchSelectionControllerImpl::GetHandle1View() {}

View* TouchSelectionControllerImpl::GetHandle2View() {}

}  // namespace views

DEFINE_ENUM_CONVERTERS()