diff options
author | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-02 07:05:41 +0000 |
---|---|---|
committer | mukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-02 07:05:41 +0000 |
commit | d7577d3f335d987262daab42d494843baf1c01b6 (patch) | |
tree | 527818a97fa3a8a7fe5b8de52a3c3800ea813219 /ash | |
parent | 48af5360104b6322b6657220df86ff62c1bf82c5 (diff) | |
download | chromium_src-d7577d3f335d987262daab42d494843baf1c01b6.zip chromium_src-d7577d3f335d987262daab42d494843baf1c01b6.tar.gz chromium_src-d7577d3f335d987262daab42d494843baf1c01b6.tar.bz2 |
Add AppListButton which is essentially an ImageButton but calls LauncherButtunHost callbacks.
BUG=133554
TEST=manually checked by hovering mouse on app-list icon.
Review URL: https://chromiumcodereview.appspot.com/10669008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@145122 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 2 | ||||
-rw-r--r-- | ash/launcher/app_list_button.cc | 79 | ||||
-rw-r--r-- | ash/launcher/app_list_button.h | 43 | ||||
-rw-r--r-- | ash/launcher/launcher_view.cc | 6 | ||||
-rw-r--r-- | ash/launcher/launcher_view_unittest.cc | 6 |
5 files changed, 131 insertions, 5 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 91efb55..2e97e94 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -70,6 +70,8 @@ 'high_contrast/high_contrast_controller.cc', 'high_contrast/high_contrast_controller.h', 'key_rewriter_delegate.h', + 'launcher/app_list_button.cc', + 'launcher/app_list_button.h', 'launcher/background_animator.cc', 'launcher/background_animator.h', 'launcher/launcher.cc', diff --git a/ash/launcher/app_list_button.cc b/ash/launcher/app_list_button.cc new file mode 100644 index 0000000..7fd67c3 --- /dev/null +++ b/ash/launcher/app_list_button.cc @@ -0,0 +1,79 @@ +// Copyright (c) 2012 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/launcher/app_list_button.h" + +#include "ash/launcher/launcher_button_host.h" +#include "ui/base/accessibility/accessible_view_state.h" +#include "ui/base/animation/animation_delegate.h" +#include "ui/base/animation/throb_animation.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/compositor/layer.h" +#include "ui/compositor/layer_animation_element.h" +#include "ui/compositor/layer_animation_observer.h" +#include "ui/compositor/layer_animation_sequence.h" +#include "ui/compositor/scoped_layer_animation_settings.h" +#include "ui/gfx/canvas.h" +#include "ui/gfx/image/image.h" +#include "ui/gfx/shadow_value.h" +#include "ui/gfx/skbitmap_operations.h" +#include "ui/gfx/transform_util.h" +#include "ui/views/controls/image_view.h" + +namespace ash { + +namespace internal { + +AppListButton::AppListButton(views::ButtonListener* listener, + LauncherButtonHost* host) + : views::ImageButton(listener), + host_(host) {} + +AppListButton::~AppListButton() { +} + +bool AppListButton::OnMousePressed(const views::MouseEvent& event) { + ImageButton::OnMousePressed(event); + host_->MousePressedOnButton(this, event); + return true; +} + +void AppListButton::OnMouseReleased(const views::MouseEvent& event) { + ImageButton::OnMouseReleased(event); + host_->MouseReleasedOnButton(this, false); +} + +void AppListButton::OnMouseCaptureLost() { + host_->MouseReleasedOnButton(this, true); + ImageButton::OnMouseCaptureLost(); +} + +bool AppListButton::OnMouseDragged(const views::MouseEvent& event) { + ImageButton::OnMouseDragged(event); + host_->MouseDraggedOnButton(this, event); + return true; +} + +void AppListButton::OnMouseMoved(const views::MouseEvent& event) { + ImageButton::OnMouseMoved(event); + host_->MouseMovedOverButton(this); +} + +void AppListButton::OnMouseEntered(const views::MouseEvent& event) { + ImageButton::OnMouseEntered(event); + host_->MouseEnteredButton(this); +} + +void AppListButton::OnMouseExited(const views::MouseEvent& event) { + ImageButton::OnMouseExited(event); + host_->MouseExitedButton(this); +} + +void AppListButton::GetAccessibleState(ui::AccessibleViewState* state) { + state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; + state->name = host_->GetAccessibleName(this); +} + +} // namespace internal +} // namespace ash diff --git a/ash/launcher/app_list_button.h b/ash/launcher/app_list_button.h new file mode 100644 index 0000000..ee1b865 --- /dev/null +++ b/ash/launcher/app_list_button.h @@ -0,0 +1,43 @@ +// Copyright (c) 2012 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_LAUNCHER_APP_LIST_BUTTON_H_ +#define ASH_LAUNCHER_APP_LIST_BUTTON_H_ +#pragma once + +#include "ui/views/controls/button/image_button.h" + +namespace ash { +namespace internal { + +class LauncherButtonHost; + +// Button used for the AppList icon on the launcher. +class AppListButton : public views::ImageButton { + public: + AppListButton(views::ButtonListener* listener, + LauncherButtonHost* host); + virtual ~AppListButton(); + + protected: + // View overrides: + virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseCaptureLost() OVERRIDE; + virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; + virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; + virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; + + private: + LauncherButtonHost* host_; + + DISALLOW_COPY_AND_ASSIGN(AppListButton); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_LAUNCHER_LAUNCHER_BUTTON_H_ diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc index ff1e992..65955d2 100644 --- a/ash/launcher/launcher_view.cc +++ b/ash/launcher/launcher_view.cc @@ -6,6 +6,7 @@ #include <algorithm> +#include "ash/launcher/app_list_button.h" #include "ash/launcher/launcher_button.h" #include "ash/launcher/launcher_delegate.h" #include "ash/launcher/launcher_icon_observer.h" @@ -506,7 +507,7 @@ views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { case TYPE_APP_LIST: { // TODO(dave): turn this into a LauncherButton too. ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - views::ImageButton* button = new views::ImageButton(this); + AppListButton* button = new AppListButton(this, this); button->SetImage( views::CustomButton::BS_NORMAL, rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToImageSkia()); @@ -734,12 +735,11 @@ void LauncherView::UpdateFirstButtonPadding() { } bool LauncherView::ShouldHideTooltip(const gfx::Point& cursor_location) { - views::View* app_list_view = GetAppListButtonView(); gfx::Rect active_bounds; for (int i = 0; i < child_count(); ++i) { views::View* child = child_at(i); - if (child == overflow_button_ || child == app_list_view) + if (child == overflow_button_) continue; gfx::Rect child_bounds = child->GetMirroredBounds(); diff --git a/ash/launcher/launcher_view_unittest.cc b/ash/launcher/launcher_view_unittest.cc index fb34c33..6d78767 100644 --- a/ash/launcher/launcher_view_unittest.cc +++ b/ash/launcher/launcher_view_unittest.cc @@ -558,9 +558,9 @@ TEST_F(LauncherViewTest, ShouldHideTooltipTest) { << "LauncherView tries to hide on button " << i; } - // The tooltip should hide on the app-list button. + // The tooltip should not hide on the app-list button. views::View* app_list_button = launcher_view_->GetAppListButtonView(); - EXPECT_TRUE(launcher_view_->ShouldHideTooltip( + EXPECT_FALSE(launcher_view_->ShouldHideTooltip( app_list_button->GetMirroredBounds().CenterPoint())); // The tooltip shouldn't hide if the mouse is in the gap between two buttons. @@ -575,6 +575,8 @@ TEST_F(LauncherViewTest, ShouldHideTooltipTest) { for (int i = 0; i < test_api_->GetButtonCount() - 1; i++) { all_area = all_area.Union(test_api_->GetButton(i)->GetMirroredBounds()); } + all_area = all_area.Union( + launcher_view_->GetAppListButtonView()->GetMirroredBounds()); EXPECT_FALSE(launcher_view_->ShouldHideTooltip(all_area.origin())); EXPECT_FALSE(launcher_view_->ShouldHideTooltip( gfx::Point(all_area.right() - 1, all_area.bottom() - 1))); |