| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/render_widget.h" | 5 #include "chrome/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include "base/gfx/point.h" | 7 #include "base/gfx/point.h" |
| 8 #include "base/gfx/size.h" | 8 #include "base/gfx/size.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/render_messages.h" |
| 14 #include "chrome/common/transport_dib.h" | 14 #include "chrome/common/transport_dib.h" |
| 15 #include "chrome/renderer/render_process.h" | 15 #include "chrome/renderer/render_process.h" |
| 16 #include "skia/ext/platform_canvas.h" | 16 #include "skia/ext/platform_canvas.h" |
| 17 #include "third_party/skia/include/core/SkShader.h" | 17 #include "third_party/skia/include/core/SkShader.h" |
| 18 #include "webkit/api/public/WebCursorInfo.h" | 18 #include "webkit/api/public/WebCursorInfo.h" |
| 19 #include "webkit/api/public/WebPopupMenuInfo.h" |
| 19 #include "webkit/api/public/WebRect.h" | 20 #include "webkit/api/public/WebRect.h" |
| 20 #include "webkit/api/public/WebScreenInfo.h" | 21 #include "webkit/api/public/WebScreenInfo.h" |
| 21 #include "webkit/api/public/WebSize.h" | 22 #include "webkit/api/public/WebSize.h" |
| 22 | 23 |
| 23 #if defined(OS_POSIX) | 24 #if defined(OS_POSIX) |
| 24 #include "third_party/skia/include/core/SkPixelRef.h" | 25 #include "third_party/skia/include/core/SkPixelRef.h" |
| 25 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 26 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
| 26 #endif // defined(OS_POSIX) | 27 #endif // defined(OS_POSIX) |
| 27 | 28 |
| 28 #include "webkit/glue/webtextdirection.h" | 29 #include "webkit/glue/webtextdirection.h" |
| 29 #include "webkit/glue/webwidget.h" | 30 #include "webkit/glue/webwidget.h" |
| 30 | 31 |
| 31 using WebKit::WebCursorInfo; | 32 using WebKit::WebCursorInfo; |
| 32 using WebKit::WebInputEvent; | 33 using WebKit::WebInputEvent; |
| 34 using WebKit::WebPopupMenuInfo; |
| 33 using WebKit::WebRect; | 35 using WebKit::WebRect; |
| 34 using WebKit::WebScreenInfo; | 36 using WebKit::WebScreenInfo; |
| 35 using WebKit::WebSize; | 37 using WebKit::WebSize; |
| 36 | 38 |
| 37 RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable) | 39 RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable) |
| 38 : routing_id_(MSG_ROUTING_NONE), | 40 : routing_id_(MSG_ROUTING_NONE), |
| 39 webwidget_(NULL), | 41 webwidget_(NULL), |
| 40 opener_id_(MSG_ROUTING_NONE), | 42 opener_id_(MSG_ROUTING_NONE), |
| 41 render_thread_(render_thread), | 43 render_thread_(render_thread), |
| 42 host_window_(NULL), | 44 host_window_(NULL), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 RenderWidget* RenderWidget::Create(int32 opener_id, | 81 RenderWidget* RenderWidget::Create(int32 opener_id, |
| 80 RenderThreadBase* render_thread, | 82 RenderThreadBase* render_thread, |
| 81 bool activatable) { | 83 bool activatable) { |
| 82 DCHECK(opener_id != MSG_ROUTING_NONE); | 84 DCHECK(opener_id != MSG_ROUTING_NONE); |
| 83 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread, | 85 scoped_refptr<RenderWidget> widget = new RenderWidget(render_thread, |
| 84 activatable); | 86 activatable); |
| 85 widget->Init(opener_id); // adds reference | 87 widget->Init(opener_id); // adds reference |
| 86 return widget; | 88 return widget; |
| 87 } | 89 } |
| 88 | 90 |
| 91 void RenderWidget::ConfigureAsExternalPopupMenu(const WebPopupMenuInfo& info) { |
| 92 popup_params_.reset(new ViewHostMsg_ShowPopup_Params); |
| 93 popup_params_->item_height = info.itemHeight; |
| 94 popup_params_->selected_item = info.selectedIndex; |
| 95 for (size_t i = 0; i < info.items.size(); ++i) |
| 96 popup_params_->popup_items.push_back(WebMenuItem(info.items[i])); |
| 97 } |
| 98 |
| 89 void RenderWidget::Init(int32 opener_id) { | 99 void RenderWidget::Init(int32 opener_id) { |
| 90 DCHECK(!webwidget_); | 100 DCHECK(!webwidget_); |
| 91 | 101 |
| 92 if (opener_id != MSG_ROUTING_NONE) | 102 if (opener_id != MSG_ROUTING_NONE) |
| 93 opener_id_ = opener_id; | 103 opener_id_ = opener_id; |
| 94 | 104 |
| 95 webwidget_ = WebWidget::Create(this); | 105 webwidget_ = WebWidget::Create(this); |
| 96 | 106 |
| 97 bool result = render_thread_->Send( | 107 bool result = render_thread_->Send( |
| 98 new ViewHostMsg_CreateWidget(opener_id, activatable_, &routing_id_)); | 108 new ViewHostMsg_CreateWidget(opener_id, activatable_, &routing_id_)); |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 WindowOpenDisposition disposition) { | 592 WindowOpenDisposition disposition) { |
| 583 DCHECK(!did_show_) << "received extraneous Show call"; | 593 DCHECK(!did_show_) << "received extraneous Show call"; |
| 584 DCHECK(routing_id_ != MSG_ROUTING_NONE); | 594 DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 585 DCHECK(opener_id_ != MSG_ROUTING_NONE); | 595 DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 586 | 596 |
| 587 if (!did_show_) { | 597 if (!did_show_) { |
| 588 did_show_ = true; | 598 did_show_ = true; |
| 589 // NOTE: initial_pos_ may still have its default values at this point, but | 599 // NOTE: initial_pos_ may still have its default values at this point, but |
| 590 // that's okay. It'll be ignored if as_popup is false, or the browser | 600 // that's okay. It'll be ignored if as_popup is false, or the browser |
| 591 // process will impose a default position otherwise. | 601 // process will impose a default position otherwise. |
| 592 render_thread_->Send(new ViewHostMsg_ShowWidget( | 602 if (popup_params_.get()) { |
| 593 opener_id_, routing_id_, initial_pos_)); | 603 popup_params_->bounds = initial_pos_; |
| 604 Send(new ViewHostMsg_ShowPopup(routing_id_, *popup_params_)); |
| 605 popup_params_.reset(); |
| 606 } else { |
| 607 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_)); |
| 608 } |
| 594 SetPendingWindowRect(initial_pos_); | 609 SetPendingWindowRect(initial_pos_); |
| 595 } | 610 } |
| 596 } | 611 } |
| 597 | 612 |
| 598 void RenderWidget::ShowAsPopupWithItems(WebWidget* webwidget, | |
| 599 const WebRect& bounds, | |
| 600 int item_height, | |
| 601 int selected_index, | |
| 602 const std::vector<WebMenuItem>& items) { | |
| 603 ViewHostMsg_ShowPopup_Params params; | |
| 604 params.bounds = bounds; | |
| 605 params.item_height = item_height; | |
| 606 params.selected_item = selected_index; | |
| 607 params.popup_items = items; | |
| 608 | |
| 609 Send(new ViewHostMsg_ShowPopup(routing_id_, params)); | |
| 610 } | |
| 611 | |
| 612 void RenderWidget::Focus(WebWidget* webwidget) { | 613 void RenderWidget::Focus(WebWidget* webwidget) { |
| 613 // Prevent the widget from stealing the focus if it does not have focus | 614 // Prevent the widget from stealing the focus if it does not have focus |
| 614 // already. We do this by explicitely setting the focus to false again. | 615 // already. We do this by explicitely setting the focus to false again. |
| 615 // We only let the browser focus the renderer. | 616 // We only let the browser focus the renderer. |
| 616 if (!has_focus_ && webwidget_) { | 617 if (!has_focus_ && webwidget_) { |
| 617 MessageLoop::current()->PostTask(FROM_HERE, | 618 MessageLoop::current()->PostTask(FROM_HERE, |
| 618 NewRunnableMethod(this, &RenderWidget::ClearFocus)); | 619 NewRunnableMethod(this, &RenderWidget::ClearFocus)); |
| 619 } | 620 } |
| 620 } | 621 } |
| 621 | 622 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 851 |
| 851 if (i == plugin_window_moves_.size()) | 852 if (i == plugin_window_moves_.size()) |
| 852 plugin_window_moves_.push_back(move); | 853 plugin_window_moves_.push_back(move); |
| 853 } | 854 } |
| 854 | 855 |
| 855 WebScreenInfo RenderWidget::GetScreenInfo(WebWidget* webwidget) { | 856 WebScreenInfo RenderWidget::GetScreenInfo(WebWidget* webwidget) { |
| 856 WebScreenInfo results; | 857 WebScreenInfo results; |
| 857 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results)); | 858 Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results)); |
| 858 return results; | 859 return results; |
| 859 } | 860 } |
| OLD | NEW |