Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "content/common/gpu/client/gl_helper.h" | 21 #include "content/common/gpu/client/gl_helper.h" |
| 22 #include "content/common/gpu/gpu_messages.h" | 22 #include "content/common/gpu/gpu_messages.h" |
| 23 #include "content/common/view_messages.h" | 23 #include "content/common/view_messages.h" |
| 24 #include "content/port/browser/render_widget_host_view_port.h" | 24 #include "content/port/browser/render_widget_host_view_port.h" |
| 25 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 28 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
| 29 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 30 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 31 #include "grit/ui_strings.h" | |
| 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" |
| 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
| 34 #include "ui/aura/client/activation_client.h" | 35 #include "ui/aura/client/activation_client.h" |
| 35 #include "ui/aura/client/aura_constants.h" | 36 #include "ui/aura/client/aura_constants.h" |
| 36 #include "ui/aura/client/cursor_client.h" | 37 #include "ui/aura/client/cursor_client.h" |
| 37 #include "ui/aura/client/focus_client.h" | 38 #include "ui/aura/client/focus_client.h" |
| 38 #include "ui/aura/client/screen_position_client.h" | 39 #include "ui/aura/client/screen_position_client.h" |
| 39 #include "ui/aura/client/stacking_client.h" | 40 #include "ui/aura/client/stacking_client.h" |
| 40 #include "ui/aura/client/tooltip_client.h" | 41 #include "ui/aura/client/tooltip_client.h" |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 941 const ViewHostMsg_SelectionBounds_Params& params) { | 942 const ViewHostMsg_SelectionBounds_Params& params) { |
| 942 if (selection_anchor_rect_ == params.anchor_rect && | 943 if (selection_anchor_rect_ == params.anchor_rect && |
| 943 selection_focus_rect_ == params.focus_rect) | 944 selection_focus_rect_ == params.focus_rect) |
| 944 return; | 945 return; |
| 945 | 946 |
| 946 selection_anchor_rect_ = params.anchor_rect; | 947 selection_anchor_rect_ = params.anchor_rect; |
| 947 selection_focus_rect_ = params.focus_rect; | 948 selection_focus_rect_ = params.focus_rect; |
| 948 | 949 |
| 949 if (GetInputMethod()) | 950 if (GetInputMethod()) |
| 950 GetInputMethod()->OnCaretBoundsChanged(this); | 951 GetInputMethod()->OnCaretBoundsChanged(this); |
| 952 if (touch_selection_controller_.get()) | |
| 953 touch_selection_controller_->SelectionChanged(); | |
| 954 } | |
| 955 | |
| 956 void RenderWidgetHostViewAura::TouchEditingHandlesVisibilityChanged( | |
| 957 bool visible) { | |
| 958 if (visible && !touch_selection_controller_.get()) { | |
| 959 touch_selection_controller_.reset( | |
| 960 ui::TouchSelectionController::create(this)); | |
| 961 } | |
| 962 if (!visible) | |
| 963 touch_selection_controller_.reset(); | |
| 964 | |
| 965 if (touch_selection_controller_.get()) | |
| 966 touch_selection_controller_->SelectionChanged(); | |
| 951 } | 967 } |
| 952 | 968 |
| 953 void RenderWidgetHostViewAura::ScrollOffsetChanged() { | 969 void RenderWidgetHostViewAura::ScrollOffsetChanged() { |
| 954 aura::RootWindow* root = window_->GetRootWindow(); | 970 aura::RootWindow* root = window_->GetRootWindow(); |
| 955 if (!root) | 971 if (!root) |
| 956 return; | 972 return; |
| 957 aura::client::CursorClient* cursor_client = | 973 aura::client::CursorClient* cursor_client = |
| 958 aura::client::GetCursorClient(root); | 974 aura::client::GetCursorClient(root); |
| 959 if (cursor_client && !cursor_client->IsCursorVisible()) | 975 if (cursor_client && !cursor_client->IsCursorVisible()) |
| 960 cursor_client->DisableMouseEvents(); | 976 cursor_client->DisableMouseEvents(); |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1642 return gfx::Size(); | 1658 return gfx::Size(); |
| 1643 } | 1659 } |
| 1644 | 1660 |
| 1645 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, | 1661 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, |
| 1646 const gfx::Rect& new_bounds) { | 1662 const gfx::Rect& new_bounds) { |
| 1647 // We care about this only in fullscreen mode, where there is no | 1663 // We care about this only in fullscreen mode, where there is no |
| 1648 // WebContentsViewAura. We are sized via SetSize() or SetBounds() by | 1664 // WebContentsViewAura. We are sized via SetSize() or SetBounds() by |
| 1649 // WebContentsViewAura in other cases. | 1665 // WebContentsViewAura in other cases. |
| 1650 if (is_fullscreen_) | 1666 if (is_fullscreen_) |
| 1651 SetSize(new_bounds.size()); | 1667 SetSize(new_bounds.size()); |
| 1668 | |
| 1669 if (touch_selection_controller_.get()) | |
| 1670 touch_selection_controller_->SelectionChanged(); | |
| 1652 } | 1671 } |
| 1653 | 1672 |
| 1654 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { | 1673 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { |
| 1655 if (mouse_locked_) | 1674 if (mouse_locked_) |
| 1656 return ui::kCursorNone; | 1675 return ui::kCursorNone; |
| 1657 return current_cursor_.GetNativeCursor(); | 1676 return current_cursor_.GetNativeCursor(); |
| 1658 } | 1677 } |
| 1659 | 1678 |
| 1660 int RenderWidgetHostViewAura::GetNonClientComponent( | 1679 int RenderWidgetHostViewAura::GetNonClientComponent( |
| 1661 const gfx::Point& point) const { | 1680 const gfx::Point& point) const { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2142 | 2161 |
| 2143 DCHECK(!shared_surface_handle_.is_null()); | 2162 DCHECK(!shared_surface_handle_.is_null()); |
| 2144 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 2163 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 2145 factory->DestroySharedSurfaceHandle(shared_surface_handle_); | 2164 factory->DestroySharedSurfaceHandle(shared_surface_handle_); |
| 2146 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); | 2165 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); |
| 2147 host_->CompositingSurfaceUpdated(); | 2166 host_->CompositingSurfaceUpdated(); |
| 2148 host_->ScheduleComposite(); | 2167 host_->ScheduleComposite(); |
| 2149 } | 2168 } |
| 2150 | 2169 |
| 2151 //////////////////////////////////////////////////////////////////////////////// | 2170 //////////////////////////////////////////////////////////////////////////////// |
| 2171 // RenderWidgetHostViewAura, ui::TouchEditable implementation: | |
| 2172 | |
| 2173 void RenderWidgetHostViewAura::SelectRect(const gfx::Point& start, | |
| 2174 const gfx::Point& end) { | |
| 2175 // Since we draw selection handles in WebKit, we should never get here. | |
| 2176 NOTREACHED(); | |
| 2177 } | |
| 2178 | |
| 2179 void RenderWidgetHostViewAura::GetSelectionEndPoints(gfx::Rect* p1, | |
| 2180 gfx::Rect* p2) { | |
| 2181 *p1 = selection_anchor_rect_; | |
| 2182 *p2 = selection_focus_rect_; | |
| 2183 } | |
| 2184 | |
| 2185 gfx::Rect RenderWidgetHostViewAura::GetBounds() { | |
| 2186 gfx::Rect bounds = GetViewBounds(); | |
| 2187 // We are supposed to return bounds in local coordinates, but GetViewBounds() | |
| 2188 // gives bounds in screen space. So we convert. | |
|
piman
2013/02/22 02:43:04
Can't we just return window_->bounds() ?
varunjain
2013/02/28 20:28:19
Done.
| |
| 2189 gfx::Point origin = bounds.origin(); | |
| 2190 ConvertPointFromScreen(&origin); | |
| 2191 bounds.set_origin(origin); | |
| 2192 return bounds; | |
| 2193 } | |
| 2194 | |
| 2195 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() { | |
| 2196 return window_->GetRootWindow(); | |
|
piman
2013/02/22 02:43:04
There is already a GetNativeView() in this class.
varunjain
2013/02/28 20:28:19
Done.
| |
| 2197 } | |
| 2198 | |
| 2199 void RenderWidgetHostViewAura::ConvertPointToScreen(gfx::Point* point) { | |
| 2200 aura::client::ScreenPositionClient* screen_position_client = | |
| 2201 aura::client::GetScreenPositionClient(window_->GetRootWindow()); | |
| 2202 if (screen_position_client) | |
| 2203 screen_position_client->ConvertPointToScreen(window_, point); | |
| 2204 } | |
| 2205 | |
| 2206 void RenderWidgetHostViewAura::ConvertPointFromScreen(gfx::Point* point) { | |
| 2207 aura::client::ScreenPositionClient* screen_position_client = | |
| 2208 aura::client::GetScreenPositionClient(window_->GetRootWindow()); | |
| 2209 if (screen_position_client) | |
| 2210 screen_position_client->ConvertPointFromScreen(window_, point); | |
| 2211 } | |
| 2212 | |
| 2213 bool RenderWidgetHostViewAura::DrawsHandles() { | |
| 2214 return true; | |
| 2215 } | |
| 2216 | |
| 2217 void RenderWidgetHostViewAura::OpenContextMenu(const gfx::Point anchor) { | |
| 2218 WebKit::WebMouseEvent mouse_event; | |
| 2219 mouse_event.button = WebKit::WebMouseEvent::ButtonRight; | |
| 2220 mouse_event.type = WebKit::WebInputEvent::MouseDown; | |
| 2221 gfx::Point local_anchor = anchor; | |
| 2222 ConvertPointFromScreen(&local_anchor); | |
| 2223 | |
| 2224 mouse_event.windowX = mouse_event.x = local_anchor.x(); | |
| 2225 mouse_event.windowY = mouse_event.y = local_anchor.y(); | |
| 2226 mouse_event.globalX = anchor.x(); | |
| 2227 mouse_event.globalY = anchor.y(); | |
| 2228 host_->ForwardMouseEvent(mouse_event); | |
|
piman
2013/02/22 02:43:04
This doesn't look reasonable - what are we trying
varunjain
2013/02/28 20:28:19
Removed. I have added proper API to webkit.
| |
| 2229 touch_selection_controller_.reset(); | |
| 2230 } | |
| 2231 | |
| 2232 bool RenderWidgetHostViewAura::IsCommandIdChecked(int command_id) const { | |
| 2233 NOTREACHED(); | |
| 2234 return false; | |
| 2235 } | |
| 2236 | |
| 2237 bool RenderWidgetHostViewAura::IsCommandIdEnabled(int command_id) const { | |
| 2238 bool editable = text_input_type_ != ui::TEXT_INPUT_TYPE_NONE; | |
| 2239 bool has_selection = !selection_range_.is_empty(); | |
| 2240 string16 result; | |
|
piman
2013/02/22 02:43:04
nit: move to IDS_APP_PASTE case (add brackets ther
varunjain
2013/02/28 20:28:19
Done.
| |
| 2241 switch (command_id) { | |
| 2242 case IDS_APP_CUT: | |
|
piman
2013/02/22 02:43:04
nit: rather than importing UI symbols here, it see
varunjain
2013/02/28 20:28:19
What would be the advantage? the enum will have to
| |
| 2243 return editable && has_selection; | |
| 2244 case IDS_APP_COPY: | |
| 2245 return has_selection; | |
| 2246 case IDS_APP_PASTE: | |
| 2247 ui::Clipboard::GetForCurrentThread()->ReadText( | |
| 2248 ui::Clipboard::BUFFER_STANDARD, &result); | |
| 2249 return editable && !result.empty(); | |
| 2250 case IDS_APP_DELETE: | |
| 2251 return editable && has_selection; | |
| 2252 case IDS_APP_SELECT_ALL: | |
| 2253 return true; | |
| 2254 default: | |
| 2255 return false; | |
| 2256 } | |
| 2257 } | |
| 2258 | |
| 2259 bool RenderWidgetHostViewAura::GetAcceleratorForCommandId( | |
| 2260 int command_id, | |
| 2261 ui::Accelerator* accelerator) { | |
| 2262 return false; | |
| 2263 } | |
| 2264 | |
| 2265 void RenderWidgetHostViewAura::ExecuteCommand(int command_id) { | |
| 2266 switch (command_id) { | |
| 2267 case IDS_APP_CUT: | |
| 2268 host_->Cut(); | |
| 2269 break; | |
| 2270 case IDS_APP_COPY: | |
| 2271 host_->Copy(); | |
| 2272 break; | |
| 2273 case IDS_APP_PASTE: | |
| 2274 host_->Paste(); | |
| 2275 break; | |
| 2276 case IDS_APP_DELETE: | |
| 2277 host_->Delete(); | |
| 2278 break; | |
| 2279 case IDS_APP_SELECT_ALL: | |
| 2280 host_->SelectAll(); | |
| 2281 break; | |
| 2282 default: | |
| 2283 NOTREACHED(); | |
| 2284 break; | |
| 2285 } | |
| 2286 touch_selection_controller_.reset(); | |
| 2287 } | |
| 2288 | |
| 2289 //////////////////////////////////////////////////////////////////////////////// | |
| 2152 // RenderWidgetHostViewAura, private: | 2290 // RenderWidgetHostViewAura, private: |
| 2153 | 2291 |
| 2154 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { | 2292 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { |
| 2155 if (paint_observer_) | 2293 if (paint_observer_) |
| 2156 paint_observer_->OnViewDestroyed(); | 2294 paint_observer_->OnViewDestroyed(); |
| 2157 if (!shared_surface_handle_.is_null()) { | 2295 if (!shared_surface_handle_.is_null()) { |
| 2158 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 2296 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 2159 factory->DestroySharedSurfaceHandle(shared_surface_handle_); | 2297 factory->DestroySharedSurfaceHandle(shared_surface_handle_); |
| 2160 factory->RemoveObserver(this); | 2298 factory->RemoveObserver(this); |
| 2161 } | 2299 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2358 RenderWidgetHost* widget) { | 2496 RenderWidgetHost* widget) { |
| 2359 return new RenderWidgetHostViewAura(widget); | 2497 return new RenderWidgetHostViewAura(widget); |
| 2360 } | 2498 } |
| 2361 | 2499 |
| 2362 // static | 2500 // static |
| 2363 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 2501 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2364 GetScreenInfoForWindow(results, NULL); | 2502 GetScreenInfoForWindow(results, NULL); |
| 2365 } | 2503 } |
| 2366 | 2504 |
| 2367 } // namespace content | 2505 } // namespace content |
| OLD | NEW |