13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file.
43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
8f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include <map>
9f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/ash_export.h"
11010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "ash/frame/caption_buttons/frame_size_button_delegate.h"
125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ui/gfx/animation/animation_delegate.h"
133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/views/controls/button/button.h"
143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/views/view.h"
153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)namespace gfx {
175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class SlideAnimation;
185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)}
195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace views {
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class Widget;
223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace ash {
253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Container view for the frame caption buttons. It performs the appropriate
273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// action when a caption button is clicked.
283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class ASH_EXPORT FrameCaptionButtonContainerView
293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    : public views::View,
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      public views::ButtonListener,
315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      public FrameSizeButtonDelegate,
325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      public gfx::AnimationDelegate {
333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public:
343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  static const char kViewClassName[];
353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Whether the frame can be minimized (either via the maximize/restore button
37424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // or via a dedicated button).
38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  enum MinimizeAllowed {
39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    MINIMIZE_ALLOWED,
40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    MINIMIZE_DISALLOWED
41424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  };
42424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
43d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // |frame| is the views::Widget that the caption buttons act on.
44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // |minimize_allowed| indicates whether the frame can be minimized (either via
45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // the maximize/restore button or via a dedicated button).
46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  FrameCaptionButtonContainerView(views::Widget* frame,
47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)                                  MinimizeAllowed minimize_allowed);
483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual ~FrameCaptionButtonContainerView();
493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // For testing.
515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  class ASH_EXPORT TestApi {
523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)   public:
533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    explicit TestApi(FrameCaptionButtonContainerView* container_view)
543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)        : container_view_(container_view) {
553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    }
563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    void EndAnimations();
585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    FrameCaptionButton* minimize_button() const {
60424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)      return container_view_->minimize_button_;
61424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
62424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    FrameCaptionButton* size_button() const {
643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      return container_view_->size_button_;
653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    }
663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    FrameCaptionButton* close_button() const {
683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      return container_view_->close_button_;
693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    }
703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)   private:
723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    FrameCaptionButtonContainerView* container_view_;
733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(TestApi);
753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  };
763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Sets the resource ids of the images to paint the button for |icon|. The
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // FrameCaptionButtonContainerView will keep track of the images to use for
79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // |icon| even if none of the buttons currently use |icon|.
80a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void SetButtonImages(CaptionButtonIcon icon,
81a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                       int icon_image_id,
82a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                       int inactive_icon_image_id,
83a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                       int hovered_background_image_id,
84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                       int pressed_background_image_id);
85a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
86a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Sets whether the buttons should be painted as active. Does not schedule
87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // a repaint.
88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void SetPaintAsActive(bool paint_as_active);
89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // Tell the window controls to reset themselves to the normal state.
913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  void ResetWindowControls();
923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
93424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // Determines the window HT* code for the caption button at |point|. Returns
94424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // HTNOWHERE if |point| is not over any of the caption buttons. |point| must
95424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // be in the coordinates of the FrameCaptionButtonContainerView.
96424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  int NonClientHitTest(const gfx::Point& point) const;
97424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
98c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Updates the size button's visibility based on whether |frame_| can be
99f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // maximized and if maximize mode is enabled. A parent view should relayout
100f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  // to reflect the change in visibility.
101f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  void UpdateSizeButtonVisibility();
102c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
103c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // views::View:
104cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual gfx::Size GetPreferredSize() const OVERRIDE;
1053551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void Layout() OVERRIDE;
1063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual const char* GetClassName() const OVERRIDE;
1073551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
1085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Overridden from gfx::AnimationDelegate:
1095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
1105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
1115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) private:
11358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  friend class FrameCaptionButtonContainerViewTest;
11458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  struct ButtonIconIds {
116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ButtonIconIds();
117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ButtonIconIds(int icon_id,
118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                  int inactive_icon_id,
119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                  int hovered_background_id,
120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                  int pressed_background_id);
121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ~ButtonIconIds();
122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    int icon_image_id;
124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    int inactive_icon_image_id;
125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    int hovered_background_image_id;
126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    int pressed_background_image_id;
127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  };
128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button
130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // will crossfade to the new icon. If |animate| is ANIMATE_NO and
131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // |icon| == |button|->icon(), the crossfade animation is progressed to the
132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // end.
133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void SetButtonIcon(FrameCaptionButton* button,
134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                     CaptionButtonIcon icon,
135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                     Animate animate);
136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Returns true if maximize mode is not enabled, and |frame_| widget delegate
1385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // can be maximized.
1395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  bool ShouldSizeButtonBeVisible() const;
1405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
141c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // views::ButtonListener:
1423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void ButtonPressed(views::Button* sender,
1433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                             const ui::Event& event) OVERRIDE;
1443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
145010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // FrameSizeButtonDelegate:
146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual bool IsMinimizeButtonVisible() const OVERRIDE;
147a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void SetButtonsToNormal(Animate animate) OVERRIDE;
148a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void SetButtonIcons(CaptionButtonIcon minimize_button_icon,
149a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                              CaptionButtonIcon close_button_icon,
150a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                              Animate animate) OVERRIDE;
151a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual const FrameCaptionButton* GetButtonClosestTo(
152a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const gfx::Point& position_in_screen) const OVERRIDE;
153a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void SetHoveredAndPressedButtons(
154a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const FrameCaptionButton* to_hover,
155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      const FrameCaptionButton* to_press) OVERRIDE;
15658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
1573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // The widget that the buttons act on.
1583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  views::Widget* frame_;
1593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
16058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // The buttons. In the normal button style, at most one of |minimize_button_|
16158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // and |size_button_| is visible.
162a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  FrameCaptionButton* minimize_button_;
163a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  FrameCaptionButton* size_button_;
164a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  FrameCaptionButton* close_button_;
1653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
166a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Mapping of the images needed to paint a button for each of the values of
167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // CaptionButtonIcon.
168a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  std::map<CaptionButtonIcon, ButtonIconIds> button_icon_id_map_;
169a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Animation that affects the position of |minimize_button_| and the
1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // visibility of |size_button_|.
1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  scoped_ptr<gfx::SlideAnimation> maximize_mode_animation_;
1735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView);
1753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
1763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)}  // namespace ash
1783551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
180