Commit e330eace authored by Ana Salazar Maldonado's avatar Ana Salazar Maldonado Committed by Commit Bot

Cros: Change size of clickable area for folder name + unit test

Users should be able to rename a folder by tapping on the folder name
or in any area near it.

Bug: 997364
Change-Id: Id2fd2e04fdce99e8323a8cdbd55d18e120e38e24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1791630Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Commit-Queue: Ana Salazar <anasalazar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697804}
parent 28027abe
......@@ -23,6 +23,7 @@
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/painter.h"
#include "ui/views/view_targeter_delegate.h"
namespace app_list {
......@@ -34,12 +35,14 @@ constexpr SkColor kFolderTitleHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0);
} // namespace
class FolderHeaderView::FolderNameView : public views::Textfield {
class FolderHeaderView::FolderNameView : public views::Textfield,
public views::ViewTargeterDelegate {
public:
explicit FolderNameView(FolderHeaderView* folder_header_view)
: folder_header_view_(folder_header_view) {
DCHECK(folder_header_view_);
SetBorder(views::CreateEmptyBorder(1, 1, 1, 1));
SetEventTargeter(std::make_unique<views::ViewTargeter>(this));
}
~FolderNameView() override = default;
......@@ -80,6 +83,15 @@ class FolderHeaderView::FolderNameView : public views::Textfield {
Textfield::OnBlur();
}
bool DoesIntersectRect(const views::View* target,
const gfx::Rect& rect) const override {
DCHECK_EQ(target, this);
gfx::Rect textfield_bounds = target->GetLocalBounds();
int horizontal_padding = -(textfield_bounds.height() * 1.5);
textfield_bounds.Inset(gfx::Insets(0, horizontal_padding));
return textfield_bounds.Intersects(rect);
}
private:
// The parent FolderHeaderView, owns this.
FolderHeaderView* folder_header_view_;
......
......@@ -20,6 +20,7 @@
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/test/event_generator.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/views_test_base.h"
......@@ -187,5 +188,41 @@ TEST_F(FolderHeaderViewTest, OemFolderNameNotEditable) {
EXPECT_FALSE(CanEditFolderName());
}
// Tests that folder name textfield is triggered when user touches on or near
// the folder name. (see https://crbug.com/997364)
TEST_F(FolderHeaderViewTest, TriggerFolderRenameAfterTappingNearFolderName) {
// Creating a folder with empty folder name.
AppListFolderItem* folder_item = model_->CreateAndPopulateFolderWithApps(2);
folder_header_view_->SetFolderItem(folder_item);
// Get in screen bounds of folder name
const gfx::Rect name_view_bounds =
folder_header_view_->GetFolderNameViewForTest()->GetBoundsInScreen();
// Tap folder name and check that folder renaming is triggered.
gfx::Point name_center_point = name_view_bounds.CenterPoint();
ui::GestureEvent tap_center(
name_center_point.x(), name_center_point.y(), 0, base::TimeTicks::Now(),
ui::GestureEventDetails(ui::EventType::ET_GESTURE_TAP_DOWN));
folder_header_view_->GetFolderNameViewForTest()->OnGestureEvent(&tap_center);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(folder_header_view_->GetFolderNameViewForTest()->HasFocus());
// Clear focus from the folder name.
widget_->GetFocusManager()->ClearFocus();
ASSERT_FALSE(folder_header_view_->GetFolderNameViewForTest()->HasFocus());
// Test that tapping near (but not directly on) the folder name still
// triggers folder rename.
// Tap folder name and check that folder renaming is triggered.
ui::GestureEvent tap_near(
name_view_bounds.top_right().x(), name_view_bounds.top_right().y(), 0,
base::TimeTicks::Now(),
ui::GestureEventDetails(ui::EventType::ET_GESTURE_TAP_DOWN));
widget_->OnGestureEvent(&tap_near);
EXPECT_TRUE(folder_header_view_->GetFolderNameViewForTest()->HasFocus());
}
} // namespace test
} // namespace app_list
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