Home | History | Annotate | Download | only in test
      1 // Copyright (c) 2012 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 UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_
      6 #define UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/compiler_specific.h"
     11 #include "third_party/skia/include/core/SkColor.h"
     12 #include "ui/aura/window_delegate.h"
     13 #include "ui/events/keycodes/keyboard_codes.h"
     14 #include "ui/gfx/rect.h"
     15 
     16 namespace aura {
     17 namespace test {
     18 
     19 // WindowDelegate implementation with all methods stubbed out.
     20 class TestWindowDelegate : public WindowDelegate {
     21  public:
     22   TestWindowDelegate();
     23   virtual ~TestWindowDelegate();
     24 
     25   // Returns a TestWindowDelegate that delete itself when
     26   // the associated window is destroyed.
     27   static TestWindowDelegate* CreateSelfDestroyingDelegate();
     28 
     29   void set_window_component(int window_component) {
     30     window_component_ = window_component;
     31   }
     32 
     33   void set_minimum_size(const gfx::Size& minimum_size) {
     34     minimum_size_ = minimum_size;
     35   }
     36 
     37   void set_maximum_size(const gfx::Size& maximum_size) {
     38     maximum_size_ = maximum_size;
     39   }
     40 
     41   // Sets the return value for CanFocus(). Default is true.
     42   void set_can_focus(bool can_focus) { can_focus_ = can_focus; }
     43 
     44   // Overridden from WindowDelegate:
     45   virtual gfx::Size GetMinimumSize() const OVERRIDE;
     46   virtual gfx::Size GetMaximumSize() const OVERRIDE;
     47   virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
     48                                const gfx::Rect& new_bounds) OVERRIDE;
     49   virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE;
     50   virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE;
     51   virtual bool ShouldDescendIntoChildForEventHandling(
     52       Window* child,
     53       const gfx::Point& location) OVERRIDE;
     54   virtual bool CanFocus() OVERRIDE;
     55   virtual void OnCaptureLost() OVERRIDE;
     56   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     57   virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
     58   virtual void OnWindowDestroying() OVERRIDE;
     59   virtual void OnWindowDestroyed() OVERRIDE;
     60   virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE;
     61   virtual bool HasHitTestMask() const OVERRIDE;
     62   virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
     63   virtual void DidRecreateLayer(ui::Layer* old_layer,
     64                                 ui::Layer* new_layer) OVERRIDE;
     65 
     66  private:
     67   int window_component_;
     68   bool delete_on_destroyed_;
     69   gfx::Size minimum_size_;
     70   gfx::Size maximum_size_;
     71   bool can_focus_;
     72 
     73   DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
     74 };
     75 
     76 // A simple WindowDelegate implementation for these tests. It owns itself
     77 // (deletes itself when the Window it is attached to is destroyed).
     78 class ColorTestWindowDelegate : public TestWindowDelegate {
     79  public:
     80   explicit ColorTestWindowDelegate(SkColor color);
     81   virtual ~ColorTestWindowDelegate();
     82 
     83   ui::KeyboardCode last_key_code() const { return last_key_code_; }
     84 
     85   // Overridden from TestWindowDelegate:
     86   virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
     87   virtual void OnWindowDestroyed() OVERRIDE;
     88   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     89 
     90  private:
     91   SkColor color_;
     92   ui::KeyboardCode last_key_code_;
     93 
     94   DISALLOW_COPY_AND_ASSIGN(ColorTestWindowDelegate);
     95 };
     96 
     97 // A simple WindowDelegate that has a hit-test mask.
     98 class MaskedWindowDelegate : public TestWindowDelegate {
     99  public:
    100   explicit MaskedWindowDelegate(const gfx::Rect mask_rect);
    101 
    102   // Overridden from TestWindowDelegate:
    103   virtual bool HasHitTestMask() const OVERRIDE;
    104   virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE;
    105 
    106  private:
    107   gfx::Rect mask_rect_;
    108 
    109   DISALLOW_COPY_AND_ASSIGN(MaskedWindowDelegate);
    110 };
    111 
    112 // Keeps track of mouse/key events.
    113 class EventCountDelegate : public TestWindowDelegate {
    114  public:
    115   EventCountDelegate();
    116 
    117   // Overridden from TestWindowDelegate:
    118   virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
    119   virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
    120 
    121   // Returns the counts of mouse motion events in the
    122   // form of "<enter> <move> <leave>".
    123   std::string GetMouseMotionCountsAndReset();
    124 
    125   // Returns the counts of mouse button events in the
    126   // form of "<press> <release>".
    127   std::string GetMouseButtonCountsAndReset();
    128 
    129   // Returns the counts of key events in the form of
    130   // "<press> <release>".
    131   std::string GetKeyCountsAndReset();
    132 
    133  private:
    134   int mouse_enter_count_;
    135   int mouse_move_count_;
    136   int mouse_leave_count_;
    137   int mouse_press_count_;
    138   int mouse_release_count_;
    139   int key_press_count_;
    140   int key_release_count_;
    141 
    142   DISALLOW_COPY_AND_ASSIGN(EventCountDelegate);
    143 };
    144 
    145 }  // namespace test
    146 }  // namespace aura
    147 
    148 #endif  // UI_AURA_TEST_TEST_WINDOW_DELEGATE_H_
    149