1a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 2a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// found in the LICENSE file. 4a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 5a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#ifndef ASH_SYSTEM_USER_BUTTON_FROM_VIEW_H_ 6a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#define ASH_SYSTEM_USER_BUTTON_FROM_VIEW_H_ 7a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 8a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "base/macros.h" 9116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "ui/gfx/insets.h" 10a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "ui/views/controls/button/custom_button.h" 11a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace ash { 13a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace tray { 14a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 15a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// This view is used to wrap it's content and transform it into button. 16a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass ButtonFromView : public views::CustomButton { 17a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch public: 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The |content| is the content which is shown within the button. The 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // |button_listener| will be informed - if provided - when a button was 20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // pressed. If |highlight_on_hover| is set to true, the button will be 21116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // highlighted upon hover and show the accessibility caret. 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The |tab_frame_inset| will be used to inset the blue tab frame inside the 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // button. 24a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ButtonFromView(views::View* content, 25a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::ButtonListener* listener, 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool highlight_on_hover, 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const gfx::Insets& tab_frame_inset); 28a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual ~ButtonFromView(); 29a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 30a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Called when the border should remain even in the non highlighted state. 31a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch void ForceBorderVisible(bool show); 32a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Overridden from views::View 34a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 35a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnFocus() OVERRIDE; 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch virtual void OnBlur() OVERRIDE; 39a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 40a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Check if the item is hovered. 41a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch bool is_hovered_for_test() { return button_hovered_; } 42a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 43a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch private: 44a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Change the hover/active state of the "button" when the status changes. 45a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch void ShowActive(); 46a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 47a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Content of button. 48a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch views::View* content_; 49a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 50a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // Whether button should be highligthed on hover. 51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch bool highlight_on_hover_; 52a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 53a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // True if button is hovered. 54a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch bool button_hovered_; 55a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 56a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // True if the border should be always visible. 57a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch bool show_border_; 58a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // The insets which get used for the drawn accessibility (tab) frame. 60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch gfx::Insets tab_frame_inset_; 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 62a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch DISALLOW_COPY_AND_ASSIGN(ButtonFromView); 63a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}; 64a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 65a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} // namespace tray 66a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch} // namespace ash 67a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 68a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#endif // ASH_SYSTEM_USER_BUTTON_FROM_VIEW_H_ 69