custom_tab.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 COMPONENTS_ARC_INTENT_HELPER_CUSTOM_TAB_H_
  5. #define COMPONENTS_ARC_INTENT_HELPER_CUSTOM_TAB_H_
  6. #include <memory>
  7. #include "ash/components/arc/arc_export.h"
  8. #include "base/scoped_observation.h"
  9. #include "ui/aura/window.h"
  10. #include "ui/aura/window_observer.h"
  11. #include "ui/gfx/native_widget_types.h"
  12. #include "ui/views/controls/native/native_view_host.h"
  13. namespace arc {
  14. // CustomTab is responsible to embed an ARC++ custom tab.
  15. class ARC_EXPORT CustomTab : public aura::WindowObserver {
  16. public:
  17. explicit CustomTab(aura::Window* arc_app_window);
  18. CustomTab(const CustomTab&) = delete;
  19. CustomTab& operator=(const CustomTab&) = delete;
  20. ~CustomTab() override;
  21. void Attach(gfx::NativeView view);
  22. // Returns the view against which a view or dialog is positioned and parented
  23. // in a CustomTab.
  24. gfx::NativeView GetHostView();
  25. // aura::WindowObserver:
  26. void OnWindowBoundsChanged(aura::Window* window,
  27. const gfx::Rect& old_bounds,
  28. const gfx::Rect& new_bounds,
  29. ui::PropertyChangeReason reason) override;
  30. void OnWindowStackingChanged(aura::Window* window) override;
  31. void OnWindowDestroying(aura::Window* window) override;
  32. private:
  33. // Updates |host_|'s bounds to deal with changes in the bounds of the
  34. // associated |arc_app_window|.
  35. void UpdateHostBounds(aura::Window* arc_app_window);
  36. // Ensures the window/layer orders for the NativeViewHost.
  37. void EnsureWindowOrders();
  38. // Converts the point from the given window to this view.
  39. void ConvertPointFromWindow(aura::Window* window, gfx::Point* point);
  40. std::unique_ptr<views::NativeViewHost> host_ =
  41. std::make_unique<views::NativeViewHost>();
  42. aura::Window* const arc_app_window_;
  43. base::ScopedObservation<aura::Window, aura::WindowObserver>
  44. arc_app_window_observation_{this};
  45. base::ScopedObservation<aura::Window, aura::WindowObserver>
  46. other_windows_observation_{this};
  47. base::WeakPtrFactory<CustomTab> weak_ptr_factory_{this};
  48. };
  49. } // namespace arc
  50. #endif // COMPONENTS_ARC_INTENT_HELPER_CUSTOM_TAB_H_