Home | History | Annotate | Download | only in views
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef APPS_UI_VIEWS_APP_WINDOW_FRAME_VIEW_H_
      6 #define APPS_UI_VIEWS_APP_WINDOW_FRAME_VIEW_H_
      7 
      8 #include <string>
      9 
     10 #include "third_party/skia/include/core/SkColor.h"
     11 #include "ui/gfx/path.h"
     12 #include "ui/gfx/rect.h"
     13 #include "ui/gfx/size.h"
     14 #include "ui/views/controls/button/button.h"
     15 #include "ui/views/window/non_client_view.h"
     16 
     17 class SkRegion;
     18 
     19 namespace extensions {
     20 class NativeAppWindow;
     21 }
     22 
     23 namespace gfx {
     24 class Canvas;
     25 class Point;
     26 }
     27 
     28 namespace ui {
     29 class Event;
     30 }
     31 
     32 namespace views {
     33 class ImageButton;
     34 class Widget;
     35 }
     36 
     37 namespace apps {
     38 
     39 // A frameless or non-Ash, non-panel NonClientFrameView for app windows.
     40 class AppWindowFrameView : public views::NonClientFrameView,
     41                            public views::ButtonListener {
     42  public:
     43   static const char kViewClassName[];
     44 
     45   // AppWindowFrameView is used to draw frames for app windows when a non
     46   // standard frame is needed. This occurs if there is no frame needed, or if
     47   // there is a frame color.
     48   // If |draw_frame| is true, the view draws its own window title area and
     49   // controls, using |frame_color|. If |draw_frame| is not true, no frame is
     50   // drawn.
     51   // TODO(benwells): Refactor this to split out frameless and colored frame
     52   // views. See http://crbug.com/359432.
     53   AppWindowFrameView(views::Widget* widget,
     54                      extensions::NativeAppWindow* window,
     55                      bool draw_frame,
     56                      const SkColor& active_frame_color,
     57                      const SkColor& inactive_frame_color);
     58   virtual ~AppWindowFrameView();
     59 
     60   void Init();
     61 
     62   void SetResizeSizes(int resize_inside_bounds_size,
     63                       int resize_outside_bounds_size,
     64                       int resize_area_corner_size);
     65   int resize_inside_bounds_size() const {
     66     return resize_inside_bounds_size_;
     67   };
     68 
     69  private:
     70   // views::NonClientFrameView implementation.
     71   virtual gfx::Rect GetBoundsForClientView() const OVERRIDE;
     72   virtual gfx::Rect GetWindowBoundsForClientBounds(
     73       const gfx::Rect& client_bounds) const OVERRIDE;
     74   virtual int NonClientHitTest(const gfx::Point& point) OVERRIDE;
     75   virtual void GetWindowMask(const gfx::Size& size,
     76                              gfx::Path* window_mask) OVERRIDE;
     77   virtual void ResetWindowControls() OVERRIDE {}
     78   virtual void UpdateWindowIcon() OVERRIDE {}
     79   virtual void UpdateWindowTitle() OVERRIDE {}
     80   virtual void SizeConstraintsChanged() OVERRIDE;
     81 
     82   // views::View implementation.
     83   virtual gfx::Size GetPreferredSize() const OVERRIDE;
     84   virtual void Layout() OVERRIDE;
     85   virtual const char* GetClassName() const OVERRIDE;
     86   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     87   virtual gfx::Size GetMinimumSize() const OVERRIDE;
     88   virtual gfx::Size GetMaximumSize() const OVERRIDE;
     89 
     90   // views::ButtonListener implementation.
     91   virtual void ButtonPressed(views::Button* sender,
     92                              const ui::Event& event) OVERRIDE;
     93 
     94   // Some button images we use depend on the color of the frame. This
     95   // will set these images based on the color of the frame.
     96   void SetButtonImagesForFrame();
     97 
     98   // Return the current frame color based on the active state of the window.
     99   SkColor CurrentFrameColor();
    100 
    101   views::Widget* widget_;
    102   extensions::NativeAppWindow* window_;
    103   bool draw_frame_;
    104   SkColor active_frame_color_;
    105   SkColor inactive_frame_color_;
    106   views::ImageButton* close_button_;
    107   views::ImageButton* maximize_button_;
    108   views::ImageButton* restore_button_;
    109   views::ImageButton* minimize_button_;
    110 
    111   // Allow resize for clicks this many pixels inside the bounds.
    112   int resize_inside_bounds_size_;
    113 
    114   // Allow resize for clicks  this many pixels outside the bounds.
    115   int resize_outside_bounds_size_;
    116 
    117   // Size in pixels of the lower-right corner resize handle.
    118   int resize_area_corner_size_;
    119 
    120   DISALLOW_COPY_AND_ASSIGN(AppWindowFrameView);
    121 };
    122 
    123 }  // namespace apps
    124 
    125 #endif  // APPS_UI_VIEWS_APP_WINDOW_FRAME_VIEW_H_
    126