browser_controls_container_view.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2019 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. #ifndef WEBLAYER_BROWSER_BROWSER_CONTROLS_CONTAINER_VIEW_H_
  5. #define WEBLAYER_BROWSER_BROWSER_CONTROLS_CONTAINER_VIEW_H_
  6. #include "base/android/scoped_java_ref.h"
  7. #include "base/memory/raw_ptr.h"
  8. #include "base/memory/scoped_refptr.h"
  9. #include "build/build_config.h"
  10. #include "content/public/browser/web_contents_observer.h"
  11. namespace cc {
  12. class UIResourceLayer;
  13. } // namespace cc
  14. namespace content {
  15. class WebContents;
  16. }
  17. namespace weblayer {
  18. class ContentViewRenderView;
  19. // Native side of BrowserControlsContainerView. Responsible for creating and
  20. // positioning the cc::Layer that contains an image of the contents of the
  21. // top-control.
  22. class BrowserControlsContainerView : public content::WebContentsObserver {
  23. public:
  24. BrowserControlsContainerView(const base::android::JavaParamRef<jobject>&
  25. java_browser_controls_container_view,
  26. ContentViewRenderView* content_view_render_view,
  27. bool is_top);
  28. BrowserControlsContainerView(const BrowserControlsContainerView&) = delete;
  29. BrowserControlsContainerView& operator=(const BrowserControlsContainerView&) =
  30. delete;
  31. ~BrowserControlsContainerView() override;
  32. // Height needed to display the control.
  33. int GetControlsHeight();
  34. // Returns the minimum height the browser controls can collapse to.
  35. int GetMinHeight();
  36. // Returns true if the browser controls should only expand when the page
  37. // contents are scrolled to the top.
  38. bool OnlyExpandControlsAtPageTop();
  39. // Returns true if height or offset changes to the browser controls should
  40. // be animated.
  41. bool ShouldAnimateBrowserControlsHeightChanges();
  42. // Returns the amount of vertical space to take away from the contents.
  43. int GetContentHeightDelta();
  44. bool IsFullyVisible() const;
  45. // Creates |controls_layer_|.
  46. void CreateControlsLayer(JNIEnv* env, int id);
  47. // Deletes |this|.
  48. void DeleteBrowserControlsContainerView(JNIEnv* env);
  49. // Deletes |controls_layer_|.
  50. void DeleteControlsLayer(JNIEnv* env);
  51. // Sets the offsets of the controls and content. See
  52. // BrowserControlsContainerView's javadoc for details on this.
  53. void SetTopControlsOffset(JNIEnv* env, int content_offset_y);
  54. void SetBottomControlsOffset(JNIEnv* env);
  55. // Sets the size of |controls_layer_|.
  56. void SetControlsSize(JNIEnv* env, int width, int height);
  57. // Triggers updating the resource (bitmap) shown in |controls_layer_|.
  58. void UpdateControlsResource(JNIEnv* env);
  59. void SetWebContents(JNIEnv* env,
  60. const base::android::JavaParamRef<jobject>& web_contents);
  61. private:
  62. // WebContentsObserver:
  63. void DidToggleFullscreenModeForTab(bool entered_fullscreen,
  64. bool will_cause_resize) override;
  65. // Only used for bottom controls.
  66. void ContentHeightChanged();
  67. int GetControlsOffset();
  68. void DoSetBottomControlsOffset();
  69. base::android::ScopedJavaGlobalRef<jobject>
  70. java_browser_controls_container_view_;
  71. raw_ptr<ContentViewRenderView> content_view_render_view_;
  72. const bool is_top_;
  73. int controls_resource_id_ = -1;
  74. // Layer containing showing the image for the controls. This is a sibling of
  75. // the WebContents layer.
  76. scoped_refptr<cc::UIResourceLayer> controls_layer_;
  77. };
  78. } // namespace weblayer
  79. #endif // WEBLAYER_BROWSER_BROWSER_CONTROLS_CONTAINER_VIEW_H_