WebOverlay.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (C) 2012, 2013 Research In Motion Limited. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef WebOverlay_h
  19. #define WebOverlay_h
  20. #include "BlackBerryGlobal.h"
  21. #include "WebOverlayOverride.h"
  22. #include <BlackBerryPlatformPrimitives.h>
  23. namespace WebCore {
  24. class GraphicsLayerClient;
  25. }
  26. namespace BlackBerry {
  27. namespace Platform {
  28. class String;
  29. }
  30. namespace WebKit {
  31. class WebAnimation;
  32. class WebOverlayClient;
  33. class WebOverlayOverride;
  34. class WebOverlayPrivate;
  35. class WebPage;
  36. /**
  37. * Represents an overlay that is rendered superimposed on a web page.
  38. *
  39. * The WebOverlay is not thread safe, but it is reentrant when used on either
  40. * the WebKit or the compositing thread. This means that overlays can be
  41. * on either of these threads, but each instance must only be used on the
  42. * thread where it was created. The only exception is the override mechanism.
  43. *
  44. * Note that WebKit thread usage of WebOverlay is obsolete and will be removed
  45. * soon.
  46. *
  47. * The WebOverlayOverride object returned by WebOverlay::override() can be used
  48. * to override the values of specific properties from the UI thread.
  49. *
  50. * They have the following semantics: If they are called for a specific overlay
  51. * on the UI thread, the value set will override any value set on the WK thread
  52. * until you call resetOverrides(). resetOverrides() is thread safe.
  53. */
  54. class BLACKBERRY_EXPORT WebOverlay {
  55. public:
  56. enum ImageDataAdoptionType {
  57. ReferenceImageData,
  58. CopyImageData
  59. };
  60. WebOverlay();
  61. WebOverlay(WebCore::GraphicsLayerClient*);
  62. virtual ~WebOverlay();
  63. // The position of the layer (the location of its top-left corner in its parent).
  64. Platform::FloatPoint position() const;
  65. void setPosition(const Platform::FloatPoint&);
  66. // Anchor point: (0, 0) is top left, (1, 1) is bottom right. The anchor point
  67. // affects the origin of the transforms.
  68. Platform::FloatPoint anchorPoint() const;
  69. void setAnchorPoint(const Platform::FloatPoint&);
  70. // The size of the layer.
  71. Platform::FloatSize size() const;
  72. void setSize(const Platform::FloatSize&);
  73. // Whether the layer is scaled together with the web page.
  74. bool sizeIsScaleInvariant() const;
  75. void setSizeIsScaleInvariant(bool);
  76. // Transform can be used to rotate the layer, among other things.
  77. Platform::TransformationMatrix transform() const;
  78. void setTransform(const Platform::TransformationMatrix&);
  79. // Opacity. Can also be used to temporarily hide a layer.
  80. float opacity() const;
  81. void setOpacity(float);
  82. // Adds/removes an animation
  83. // Note that WebAnimation and BlackBerry::Platform::String are not thread safe and have to be
  84. // created on the thread where they'll be used.
  85. void addAnimation(const WebAnimation&);
  86. void removeAnimation(const BlackBerry::Platform::String& name);
  87. // Returns the rectangle occupied by this overlay, in pixels, relative to the current viewport
  88. // Can be used for hit testing (noting though, that the overlay may have transparent pixels that
  89. // cause it not to occupy the whole rectangle, for example when the overlay draws an image with
  90. // alpha channel). Not implemented for WebKit-thread overlays.
  91. Platform::IntRect pixelViewportRect() const;
  92. WebOverlay* parent() const;
  93. bool addChild(WebOverlay*);
  94. void removeFromParent();
  95. void setContentsToImage(const unsigned char* data, const Platform::IntSize& imageSize, ImageDataAdoptionType = ReferenceImageData);
  96. void setContentsToColor(int r, int g, int b, int a);
  97. void setDrawsContent(bool);
  98. // Will result in a future call to WebOverlayClient::drawContents, if the layer draws custom contents.
  99. void invalidate();
  100. // The client can be used to draw layer contents.
  101. void setClient(WebOverlayClient*);
  102. // Must be called on UI thread.
  103. WebOverlayOverride* override();
  104. /**
  105. * Thread safe. Next time the attributes are changed on the WK thread, make
  106. * those values override any set on the UI thread.
  107. */
  108. void resetOverrides();
  109. private:
  110. friend class WebPage;
  111. friend class WebOverlayPrivate;
  112. // Disable copy constructor and operator=.
  113. WebOverlay(const WebOverlay&);
  114. WebOverlay& operator=(const WebOverlay&);
  115. WebOverlayPrivate* d;
  116. };
  117. }
  118. }
  119. #endif // WebOverlay_h