Commit bf364393 authored by Yulun Wu's avatar Yulun Wu Committed by Commit Bot

Refactor drag handle into its own class.

Bug: 1034168
Change-Id: I1551a4cbf59669c514f46e17919fe7e91bc7bbd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020561
Commit-Queue: Yulun Wu <yulunwu@chromium.org>
Auto-Submit: Yulun Wu <yulunwu@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736020}
parent 5e5f4164
......@@ -576,6 +576,8 @@ component("ash") {
"shelf/assistant_overlay.h",
"shelf/back_button.cc",
"shelf/back_button.h",
"shelf/drag_handle.cc",
"shelf/drag_handle.h",
"shelf/home_button.cc",
"shelf/home_button.h",
"shelf/home_button_controller.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/drag_handle.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "base/bind.h"
#include "base/timer/timer.h"
#include "ui/gfx/color_palette.h"
namespace ash {
namespace {
// Vertical padding to make the drag handle easier to tap.
constexpr int kVerticalClickboxPadding = 15;
} // namespace
DragHandle::DragHandle(gfx::Size drag_handle_size,
AshColorProvider::RippleAttributes ripple_attributes,
int drag_handle_corner_radius) {
SetPaintToLayer(ui::LAYER_SOLID_COLOR);
layer()->SetColor(ripple_attributes.base_color);
// TODO(manucornet): Figure out why we need a manual opacity adjustment
// to make this color look the same as the status area highlight.
layer()->SetOpacity(ripple_attributes.inkdrop_opacity + 0.075);
layer()->SetRoundedCornerRadius(
{drag_handle_corner_radius, drag_handle_corner_radius,
drag_handle_corner_radius, drag_handle_corner_radius});
SetSize(drag_handle_size);
SetEventTargeter(std::make_unique<views::ViewTargeter>(this));
}
DragHandle::~DragHandle() = default;
bool DragHandle::DoesIntersectRect(const views::View* target,
const gfx::Rect& rect) const {
DCHECK_EQ(target, this);
gfx::Rect drag_handle_bounds = target->GetLocalBounds();
drag_handle_bounds.set_y(drag_handle_bounds.y() - kVerticalClickboxPadding);
drag_handle_bounds.set_height(drag_handle_bounds.height() +
2 * kVerticalClickboxPadding);
return drag_handle_bounds.Intersects(rect);
}
} // namespace ash
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_DRAG_HANDLE_H_
#define ASH_SHELF_DRAG_HANDLE_H_
#include "ash/ash_export.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/style/ash_color_provider.h"
#include "base/timer/timer.h"
#include "ui/views/view.h"
#include "ui/views/view_targeter_delegate.h"
namespace ash {
class ASH_EXPORT DragHandle : public views::View,
public views::ViewTargeterDelegate {
public:
explicit DragHandle(gfx::Size drag_handle_size,
AshColorProvider::RippleAttributes ripple_attributes,
int drag_handle_corner_radius);
DragHandle(const DragHandle&) = delete;
~DragHandle() override;
DragHandle& operator=(const DragHandle&) = delete;
// views::ViewTargeterDelegate:
bool DoesIntersectRect(const views::View* target,
const gfx::Rect& rect) const override;
};
} // namespace ash
#endif // ASH_SHELF_DRAG_HANDLE_H_
......@@ -17,6 +17,7 @@
#include "ash/public/cpp/window_properties.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shelf/drag_handle.h"
#include "ash/shelf/home_button.h"
#include "ash/shelf/hotseat_transition_animator.h"
#include "ash/shelf/hotseat_widget.h"
......@@ -165,7 +166,7 @@ class ShelfWidget::DelegateView : public views::WidgetDelegate,
// A drag handle shown in tablet mode when we are not on the home screen.
// Owned by the view hierarchy.
views::View* drag_handle_ = nullptr;
DragHandle* drag_handle_ = nullptr;
// When true, the default focus of the shelf is the last focusable child.
bool default_last_focusable_child_ = false;
......@@ -197,26 +198,18 @@ ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget)
ShowAnimatingBackground(false);
animating_background_.SetColor(ShelfConfig::Get()->GetMaximizedShelfColor());
std::unique_ptr<views::View> drag_handle_ptr =
std::make_unique<views::View>();
const int radius = kDragHandleCornerRadius;
const AshColorProvider::RippleAttributes ripple_attributes =
AshColorProvider::Get()->GetRippleAttributes(
ShelfConfig::Get()->GetDefaultShelfColor());
drag_handle_ = AddChildView(std::move(drag_handle_ptr));
drag_handle_->SetPaintToLayer(ui::LAYER_SOLID_COLOR);
drag_handle_->layer()->SetColor(ripple_attributes.base_color);
// TODO(manucornet): Figure out why we need a manual opacity adjustment
// to make this color look the same as the status area highlight.
drag_handle_->layer()->SetOpacity(ripple_attributes.inkdrop_opacity + 0.075);
drag_handle_->layer()->SetRoundedCornerRadius(
{radius, radius, radius, radius});
drag_handle_->SetSize(kDragHandleSize);
drag_handle_ = AddChildView(std::make_unique<DragHandle>(
kDragHandleSize, ripple_attributes, kDragHandleCornerRadius));
animating_drag_handle_.SetColor(ripple_attributes.base_color);
animating_drag_handle_.SetOpacity(ripple_attributes.inkdrop_opacity + 0.075);
animating_drag_handle_.SetRoundedCornerRadius(
{radius, radius, radius, radius});
{kDragHandleCornerRadius, kDragHandleCornerRadius,
kDragHandleCornerRadius, kDragHandleCornerRadius});
}
ShelfWidget::DelegateView::~DelegateView() = default;
......
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