painted_scrollbar_layer.h revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
1// Copyright 2013 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_PAINTED_SCROLLBAR_LAYER_H_ 6#define CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ 7 8#include "cc/base/cc_export.h" 9#include "cc/input/scrollbar.h" 10#include "cc/layers/contents_scaling_layer.h" 11#include "cc/layers/scrollbar_theme_painter.h" 12#include "cc/resources/layer_updater.h" 13#include "cc/resources/scoped_ui_resource.h" 14 15namespace cc { 16class ScrollbarThemeComposite; 17 18class CC_EXPORT PaintedScrollbarLayer : public ContentsScalingLayer { 19 public: 20 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) 21 OVERRIDE; 22 23 static scoped_refptr<PaintedScrollbarLayer> Create( 24 scoped_ptr<Scrollbar> scrollbar, 25 int scroll_layer_id); 26 27 int scroll_layer_id() const { return scroll_layer_id_; } 28 void SetScrollLayerId(int id); 29 30 virtual bool OpacityCanAnimateOnImplThread() const OVERRIDE; 31 32 ScrollbarOrientation Orientation() const; 33 34 // Layer interface 35 virtual bool Update(ResourceUpdateQueue* queue, 36 const OcclusionTracker* occlusion) OVERRIDE; 37 virtual void SetLayerTreeHost(LayerTreeHost* host) OVERRIDE; 38 virtual void PushPropertiesTo(LayerImpl* layer) OVERRIDE; 39 virtual void CalculateContentsScale(float ideal_contents_scale, 40 float device_scale_factor, 41 float page_scale_factor, 42 bool animating_transform_to_screen, 43 float* contents_scale_x, 44 float* contents_scale_y, 45 gfx::Size* content_bounds) OVERRIDE; 46 47 virtual PaintedScrollbarLayer* ToScrollbarLayer() OVERRIDE; 48 49 protected: 50 PaintedScrollbarLayer(scoped_ptr<Scrollbar> scrollbar, int scroll_layer_id); 51 virtual ~PaintedScrollbarLayer(); 52 53 // For unit tests 54 UIResourceId track_resource_id() { 55 return track_resource_.get() ? track_resource_->id() : 0; 56 } 57 UIResourceId thumb_resource_id() { 58 return thumb_resource_.get() ? thumb_resource_->id() : 0; 59 } 60 void UpdateThumbAndTrackGeometry(); 61 62 private: 63 gfx::Rect ScrollbarLayerRectToContentRect(gfx::Rect layer_rect) const; 64 gfx::Rect OriginThumbRect() const; 65 66 int MaxTextureSize(); 67 float ClampScaleToMaxTextureSize(float scale); 68 69 scoped_refptr<UIResourceBitmap> RasterizeScrollbarPart(gfx::Rect rect, 70 ScrollbarPart part); 71 72 scoped_ptr<Scrollbar> scrollbar_; 73 74 // Snapshot of properties taken in UpdateThumbAndTrackGeometry and used in 75 // PushPropertiesTo. 76 int thumb_thickness_; 77 int thumb_length_; 78 gfx::Point location_; 79 gfx::Rect track_rect_; 80 81 int scroll_layer_id_; 82 83 scoped_ptr<ScopedUIResource> track_resource_; 84 scoped_ptr<ScopedUIResource> thumb_resource_; 85 86 DISALLOW_COPY_AND_ASSIGN(PaintedScrollbarLayer); 87}; 88 89} // namespace cc 90 91#endif // CC_LAYERS_PAINTED_SCROLLBAR_LAYER_H_ 92