Advertisement
Guest User

Untitled

a guest
Nov 25th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.32 KB | None | 0 0
  1. // Copyright (c) 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 CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_
  6. #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_
  7.  
  8. #include <gdk/gdk.h>
  9.  
  10. #include <string>
  11. #include <vector>
  12.  
  13. #include "base/memory/scoped_ptr.h"
  14. #include "base/time/time.h"
  15. #include "content/browser/accessibility/browser_accessibility_manager.h"
  16. #include "content/browser/renderer_host/gtk_plugin_container_manager.h"
  17. #include "content/browser/renderer_host/render_widget_host_view_base.h"
  18. #include "content/common/content_export.h"
  19. #include "ipc/ipc_sender.h"
  20. #include "ui/base/animation/animation_delegate.h"
  21. #include "ui/base/animation/slide_animation.h"
  22. #include "ui/base/gtk/gtk_signal.h"
  23. #include "ui/base/gtk/gtk_signal_registrar.h"
  24. #include "ui/base/gtk/owned_widget_gtk.h"
  25. #include "ui/base/x/active_window_watcher_x_observer.h"
  26. #include "ui/gfx/native_widget_types.h"
  27. #include "ui/gfx/point.h"
  28. #include "ui/gfx/rect.h"
  29. #include "webkit/common/cursors/webcursor.h"
  30.  
  31. typedef struct _GtkClipboard GtkClipboard;
  32. typedef struct _GtkSelectionData GtkSelectionData;
  33.  
  34. namespace content {
  35. class GtkIMContextWrapper;
  36. class GtkKeyBindingsHandler;
  37. class RenderWidgetHost;
  38. class RenderWidgetHostImpl;
  39. struct NativeWebKeyboardEvent;
  40.  
  41. // -----------------------------------------------------------------------------
  42. // See comments in render_widget_host_view.h about this class and its members.
  43. // -----------------------------------------------------------------------------
  44. class CONTENT_EXPORT RenderWidgetHostViewGtk
  45.     : public RenderWidgetHostViewBase,
  46.       public BrowserAccessibilityDelegate,
  47.       public ui::ActiveWindowWatcherXObserver,
  48.       public IPC::Sender {
  49.  public:
  50.   virtual ~RenderWidgetHostViewGtk();
  51.  
  52.   // RenderWidgetHostView implementation.
  53.   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
  54.   virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE;
  55.   virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
  56.   virtual void SetSize(const gfx::Size& size) OVERRIDE;
  57.   virtual void SetBounds(const gfx::Rect& rect) OVERRIDE;
  58.   virtual gfx::NativeView GetNativeView() const OVERRIDE;
  59.   virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
  60.   virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
  61.   virtual bool HasFocus() const OVERRIDE;
  62.   virtual bool IsSurfaceAvailableForCopy() const OVERRIDE;
  63.   virtual void Show() OVERRIDE;
  64.   virtual void Hide() OVERRIDE;
  65.   virtual bool IsShowing() OVERRIDE;
  66.   virtual gfx::Rect GetViewBounds() const OVERRIDE;
  67.   virtual GdkEventButton* GetLastMouseDown() OVERRIDE;
  68.   virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE;
  69.   virtual void SetBackground(const SkBitmap& background) OVERRIDE;
  70.  
  71.   // RenderWidgetHostViewPort implementation.
  72.   virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
  73.                            const gfx::Rect& pos) OVERRIDE;
  74.   virtual void InitAsFullscreen(
  75.       RenderWidgetHostView* reference_host_view) OVERRIDE;
  76.   virtual void WasShown() OVERRIDE;
  77.   virtual void WasHidden() OVERRIDE;
  78.   virtual void MovePluginWindows(
  79.       const gfx::Vector2d& scroll_offset,
  80.       const std::vector<WebPluginGeometry>& moves) OVERRIDE;
  81.   virtual void Focus() OVERRIDE;
  82.   virtual void Blur() OVERRIDE;
  83.   virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE;
  84.   virtual void SetIsLoading(bool is_loading) OVERRIDE;
  85.   virtual void TextInputTypeChanged(ui::TextInputType type,
  86.                                     ui::TextInputMode input_mode,
  87.                                     bool can_compose_inline) OVERRIDE;
  88.   virtual void ImeCancelComposition() OVERRIDE;
  89.   virtual void DidUpdateBackingStore(
  90.       const gfx::Rect& scroll_rect,
  91.       const gfx::Vector2d& scroll_delta,
  92.       const std::vector<gfx::Rect>& copy_rects,
  93.       const ui::LatencyInfo& latency_info) OVERRIDE;
  94.   virtual void RenderProcessGone(base::TerminationStatus status,
  95.                                  int error_code) OVERRIDE;
  96.   virtual void Destroy() OVERRIDE;
  97.   virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) {}
  98.   virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE;
  99.   virtual void SelectionChanged(const string16& text,
  100.                                 size_t offset,
  101.                                 const ui::Range& range,
  102.                                 const gfx::Range& range) OVERRIDE;
  103.   virtual void SelectionBoundsChanged(
  104.       const ViewHostMsg_SelectionBounds_Params& params) OVERRIDE;
  105.   virtual void ScrollOffsetChanged() OVERRIDE;
  106.   virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
  107.   virtual void CopyFromCompositingSurface(
  108.       const gfx::Rect& src_subrect,
  109.       const gfx::Size& dst_size,
  110.       const base::Callback<void(bool, const SkBitmap&)>& callback) OVERRIDE;
  111.   virtual void CopyFromCompositingSurfaceToVideoFrame(
  112.       const gfx::Rect& src_subrect,
  113.       const scoped_refptr<media::VideoFrame>& target,
  114.       const base::Callback<void(bool)>& callback) OVERRIDE;
  115.   virtual bool CanCopyToVideoFrame() const OVERRIDE;
  116.   virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
  117.   virtual void AcceleratedSurfaceBuffersSwapped(
  118.       const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
  119.       int gpu_host_id) OVERRIDE;
  120.   virtual void AcceleratedSurfacePostSubBuffer(
  121.       const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
  122.       int gpu_host_id) OVERRIDE;
  123.   virtual void AcceleratedSurfaceSuspend() OVERRIDE;
  124.   virtual void AcceleratedSurfaceRelease() OVERRIDE;
  125.   virtual bool HasAcceleratedSurface(const gfx::Size& desired_size) OVERRIDE;
  126.   virtual void SetHasHorizontalScrollbar(
  127.       bool has_horizontal_scrollbar) OVERRIDE;
  128.   virtual void SetScrollOffsetPinning(
  129.       bool is_pinned_to_left, bool is_pinned_to_right) OVERRIDE;
  130.   virtual void GetScreenInfo(WebKit::WebScreenInfo* results) OVERRIDE;
  131.   virtual gfx::Rect GetBoundsInRootWindow() OVERRIDE;
  132.   virtual gfx::GLSurfaceHandle GetCompositingSurface() OVERRIDE;
  133.   virtual bool LockMouse() OVERRIDE;
  134.   virtual void UnlockMouse() OVERRIDE;
  135.   virtual void OnAccessibilityNotifications(
  136.       const std::vector<AccessibilityHostMsg_NotificationParams>& params)
  137.       OVERRIDE;
  138.   virtual void OnAccessibilityEvents(
  139.       const std::vector<AccessibilityHostMsg_EventParams>& params)
  140.       OVERRIDE;
  141.  
  142.   // ActiveWindowWatcherXObserver implementation.
  143.   virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE;
  144.  
  145.   // IPC::Sender implementation:
  146.   virtual bool Send(IPC::Message* message) OVERRIDE;
  147.  
  148.   // If the widget is aligned with an edge of the monitor its on and the user
  149.   // attempts to drag past that edge we track the number of times it has
  150.   // occurred, so that we can force the widget to scroll when it otherwise
  151.   // would be unable to.
  152.   void ModifyEventForEdgeDragging(GtkWidget* widget, GdkEventMotion* event);
  153.  
  154.   // Mouse events always provide a movementX/Y which needs to be computed.
  155.   // Also, mouse lock requires knowledge of last unlocked cursor coordinates.
  156.   // State is stored on the host view to do this, and the mouse event modified.
  157.   void ModifyEventMovementAndCoords(WebKit::WebMouseEvent* event);
  158.  
  159.   void Paint(const gfx::Rect&);
  160.  
  161.   // Called by GtkIMContextWrapper to forward a keyboard event to renderer.
  162.   // On Linux (not ChromeOS):
  163.   // Before calling RenderWidgetHost::ForwardKeyboardEvent(), this method
  164.   // calls GtkKeyBindingsHandler::Match() against the event and send matched
  165.   // edit commands to renderer by calling
  166.   // RenderWidgetHost::ForwardEditCommandsForNextKeyEvent().
  167.   void ForwardKeyboardEvent(const NativeWebKeyboardEvent& event);
  168.  
  169.   bool RetrieveSurrounding(std::string* text, size_t* cursor_index);
  170.  
  171.   // BrowserAccessibilityDelegate implementation.
  172.   virtual void SetAccessibilityFocus(int acc_obj_id) OVERRIDE;
  173.   virtual void AccessibilityDoDefaultAction(int acc_obj_id) OVERRIDE;
  174.   virtual void AccessibilityScrollToMakeVisible(
  175.       int acc_obj_id, gfx::Rect subfocus) OVERRIDE;
  176.   virtual void AccessibilityScrollToPoint(
  177.       int acc_obj_id, gfx::Point point) OVERRIDE;
  178.   virtual void AccessibilitySetTextSelection(
  179.       int acc_obj_id, int start_offset, int end_offset) OVERRIDE;
  180.   virtual gfx::Point GetLastTouchEventLocation() const OVERRIDE;
  181.   virtual void FatalAccessibilityTreeError() OVERRIDE;
  182.  
  183.   // Get the root of the AtkObject* tree for accessibility.
  184.   AtkObject* GetAccessible();
  185.  
  186.  protected:
  187.   friend class RenderWidgetHostView;
  188.  
  189.   // Should construct only via RenderWidgetHostView::CreateViewForWidget.
  190.   explicit RenderWidgetHostViewGtk(RenderWidgetHost* widget);
  191.  
  192.  private:
  193.   friend class RenderWidgetHostViewGtkWidget;
  194.  
  195.   CHROMEGTK_CALLBACK_0(RenderWidgetHostViewGtk,
  196.                        void,
  197.                        OnDestroy);
  198.  
  199.   // Returns whether the widget needs an input grab (GTK+ and X) to work
  200.   // properly.
  201.   bool NeedsInputGrab();
  202.  
  203.   // Returns whether this render view is a popup (<select> dropdown or
  204.   // autocomplete window).
  205.   bool IsPopup() const;
  206.  
  207.   // Do initialization needed by all InitAs*() methods.
  208.   void DoSharedInit();
  209.  
  210.   // Do initialization needed just by InitAsPopup() and InitAsFullscreen().
  211.   // We move and resize |window| to |bounds| and show it and its contents.
  212.   void DoPopupOrFullscreenInit(GtkWindow* window, const gfx::Rect& bounds);
  213.  
  214.   // Update the display cursor for the render view.
  215.   void ShowCurrentCursor();
  216.  
  217.   void set_last_mouse_down(GdkEventButton* event);
  218.  
  219.   // Cause the next query for the widget center to recompute the cached value.
  220.   void MarkCachedWidgetCenterStale();
  221.  
  222.   void OnCreatePluginContainer(gfx::PluginWindowHandle id);
  223.   void OnDestroyPluginContainer(gfx::PluginWindowHandle id);
  224.  
  225.   gfx::Point GetWidgetCenter();
  226.  
  227.   // The model object.
  228.   RenderWidgetHostImpl* host_;
  229.  
  230.   // The native UI widget.
  231.   ui::OwnedWidgetGtk view_;
  232.  
  233.   // This is true when we are currently painting and thus should handle extra
  234.   // paint requests by expanding the invalid rect rather than actually
  235.   // painting.
  236.   bool about_to_validate_and_paint_;
  237.  
  238.   // This is the rectangle which we'll paint.
  239.   gfx::Rect invalid_rect_;
  240.  
  241.   // Whether or not this widget is hidden.
  242.   bool is_hidden_;
  243.  
  244.   // Whether we are currently loading.
  245.   bool is_loading_;
  246.  
  247.   // The cursor for the page. This is passed up from the renderer.
  248.   WebCursor current_cursor_;
  249.  
  250.   // The time at which this view started displaying white pixels as a result of
  251.   // not having anything to paint (empty backing store from renderer). This
  252.   // value returns true for is_null() if we are not recording whiteout times.
  253.   base::TimeTicks whiteout_start_time_;
  254.  
  255.   // The time it took after this view was selected for it to be fully painted.
  256.   base::TimeTicks web_contents_switch_paint_time_;
  257.  
  258.   // The native view of our parent widget.  Used only for popups.
  259.   GtkWidget* parent_;
  260.  
  261.   // We ignore the first mouse release on popups so the popup will remain open.
  262.   bool is_popup_first_mouse_release_;
  263.  
  264.   // Whether or not this widget's input context was focused before being
  265.   // shadowed by another widget. Used in OnGrabNotify() handler to track the
  266.   // focused state correctly.
  267.   bool was_imcontext_focused_before_grab_;
  268.  
  269.   // True if we are responsible for creating an X grab. This will only be used
  270.   // for <select> dropdowns. It should be true for most such cases, but false
  271.   // for extension popups.
  272.   bool do_x_grab_;
  273.  
  274.   // Is the widget fullscreen?
  275.   bool is_fullscreen_;
  276.  
  277.   // Has the window ever been marked active? Only valid for fullscreen or
  278.   // popup windows.
  279.   bool made_active_;
  280.  
  281.   // Used to record the last position of the mouse.
  282.   // While the mouse is locked, they store the last known position just as mouse
  283.   // lock was entered.
  284.   // Relative to the upper-left corner of the view.
  285.   gfx::Point unlocked_mouse_position_;
  286.   // Relative to the upper-left corner of the screen.
  287.   gfx::Point unlocked_global_mouse_position_;
  288.   // Last hidden cursor position. Relative to screen.
  289.   gfx::Point global_mouse_position_;
  290.   // Indicates when mouse motion is valid after the widget has moved.
  291.   bool mouse_has_been_warped_to_new_center_;
  292.   // Indicates the cursor has been warped to the unlocked position,
  293.   // but a move event has not yet been received for it there.
  294.   bool mouse_is_being_warped_to_unlocked_position_;
  295.  
  296.   // For full-screen windows we have a OnDestroy handler that we need to remove,
  297.   // so we keep it ID here.
  298.   unsigned long destroy_handler_id_;
  299.  
  300.   // A convenience wrapper object for GtkIMContext;
  301.   scoped_ptr<GtkIMContextWrapper> im_context_;
  302.  
  303.   // A convenience object for handling editor key bindings defined in gtk
  304.   // keyboard theme.
  305.   scoped_ptr<GtkKeyBindingsHandler> key_bindings_handler_;
  306.  
  307.   // Helper class that lets us allocate plugin containers and move them.
  308.   GtkPluginContainerManager plugin_container_manager_;
  309.  
  310.   // The size that we want the renderer to be.  We keep this in a separate
  311.   // variable because resizing in GTK+ is async.
  312.   gfx::Size requested_size_;
  313.  
  314.   // The latest reported center of the widget, use GetWidgetCenter() to access.
  315.   gfx::Point widget_center_;
  316.   // If the window moves the widget_center will not be valid until we recompute.
  317.   bool widget_center_valid_;
  318.  
  319.   // The number of times the user has dragged against horizontal edge  of the
  320.   // monitor (if the widget is aligned with that edge). Negative values
  321.   // indicate the left edge, positive the right.
  322.   int dragged_at_horizontal_edge_;
  323.  
  324.   // The number of times the user has dragged against vertical edge  of the
  325.   // monitor (if the widget is aligned with that edge). Negative values
  326.   // indicate the top edge, positive the bottom.
  327.   int dragged_at_vertical_edge_;
  328.  
  329.   gfx::PluginWindowHandle compositing_surface_;
  330.  
  331.   // The event for the last mouse down we handled. We need this for context
  332.   // menus and drags.
  333.   GdkEventButton* last_mouse_down_;
  334.  
  335.   // Instance of accessibility information for the root of the AtkObject
  336.   // tree representation of the WebKit render tree.
  337.   scoped_ptr<BrowserAccessibilityManager> browser_accessibility_manager_;
  338.  
  339.   ui::GtkSignalRegistrar signals_;
  340.  
  341.   ui::LatencyInfo software_latency_info_;
  342. };
  343.  
  344. }  // namespace content
  345.  
  346. #endif  // CHROME_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_GTK_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement