nine_patch_layer_impl.h revision 58537e28ecd584eab876aee8be7156509866d23a
1// Copyright 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 CC_LAYERS_NINE_PATCH_LAYER_IMPL_H_
6#define CC_LAYERS_NINE_PATCH_LAYER_IMPL_H_
7
8#include <string>
9
10#include "cc/base/cc_export.h"
11#include "cc/layers/layer_impl.h"
12#include "cc/resources/resource_provider.h"
13#include "cc/resources/ui_resource_client.h"
14#include "ui/gfx/rect.h"
15#include "ui/gfx/size.h"
16
17namespace base {
18class DictionaryValue;
19}
20
21namespace cc {
22
23class CC_EXPORT NinePatchLayerImpl : public LayerImpl {
24 public:
25  static scoped_ptr<NinePatchLayerImpl> Create(LayerTreeImpl* tree_impl,
26                                               int id) {
27    return make_scoped_ptr(new NinePatchLayerImpl(tree_impl, id));
28  }
29  virtual ~NinePatchLayerImpl();
30
31
32  void SetUIResourceId(UIResourceId uid);
33
34  // The bitmap stretches out the bounds of the layer.  The following picture
35  // illustrates the parameters associated with the dimensions.
36  //
37  // Layer space layout              Bitmap space layout
38  //
39  // ------------------------       ~~~~~~~~~~ W ~~~~~~~~~~
40  // |          :           |       :     :                |
41  // |          C           |       :     Y                |
42  // |          :           |       :     :                |
43  // |     ------------     |       :~~X~~------------     |
44  // |     |          |     |       :     |          :     |
45  // |     |          |     |       :     |          :     |
46  // |~~A~~|          |~~B~~|       H     |          Q     |
47  // |     |          |     |       :     |          :     |
48  // |     ------------     |       :     ~~~~~P~~~~~      |
49  // |          :           |       :                      |
50  // |          D           |       :                      |
51  // |          :           |       :                      |
52  // ------------------------       ------------------------
53  //
54  // |image_bounds| = (W, H)
55  // |image_aperture| = (X, Y, P, Q)
56  // |border| = (A, C, A + B, C + D)
57  // |fill_center| indicates whether to draw the center quad or not.
58  void SetLayout(gfx::Size image_bounds,
59                 gfx::Rect image_aperture,
60                 gfx::Rect border,
61                 bool fill_center);
62
63  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl)
64      OVERRIDE;
65  virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE;
66
67  virtual bool WillDraw(DrawMode draw_mode,
68                        ResourceProvider* resource_provider) OVERRIDE;
69  virtual void AppendQuads(QuadSink* quad_sink,
70                           AppendQuadsData* append_quads_data) OVERRIDE;
71  virtual ResourceProvider::ResourceId ContentsResourceId() const OVERRIDE;
72
73  virtual base::DictionaryValue* LayerTreeAsJson() const OVERRIDE;
74
75 protected:
76  NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id);
77
78 private:
79  virtual const char* LayerTypeAsString() const OVERRIDE;
80
81  // The size of the NinePatch bitmap in pixels.
82  gfx::Size image_bounds_;
83
84  // The transparent center region that shows the parent layer's contents in
85  // image space.
86  gfx::Rect image_aperture_;
87
88  // An inset border that the patches will be mapped to.
89  gfx::Rect border_;
90
91  bool fill_center_;
92
93  UIResourceId ui_resource_id_;
94
95  DISALLOW_COPY_AND_ASSIGN(NinePatchLayerImpl);
96};
97
98}  // namespace cc
99
100#endif  // CC_LAYERS_NINE_PATCH_LAYER_IMPL_H_
101