OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 #include "content/browser/tab_contents/tab_contents_view_win.h" |
| 6 |
| 7 #include "content/browser/renderer_host/render_widget_host_view_win.h" |
| 8 #include "content/browser/tab_contents/constrained_window.h" |
| 9 #include "content/browser/tab_contents/interstitial_page.h" |
| 10 #include "content/browser/tab_contents/tab_contents.h" |
| 11 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 12 |
| 13 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) |
| 14 : tab_contents_(tab_contents), |
| 15 view_(NULL) { |
| 16 } |
| 17 |
| 18 TabContentsViewWin::~TabContentsViewWin() { |
| 19 } |
| 20 |
| 21 void TabContentsViewWin::CreateView(const gfx::Size& initial_size) { |
| 22 // temporary until we specify parent |
| 23 set_window_style(WS_CAPTION | WS_VISIBLE | WS_SYSMENU); |
| 24 set_window_ex_style(WS_EX_APPWINDOW); |
| 25 |
| 26 // TODO(jam): specify a correct parent! |
| 27 Init(NULL, gfx::Rect(initial_size)); |
| 28 } |
| 29 |
| 30 RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( |
| 31 RenderWidgetHost* render_widget_host) { |
| 32 if (view_) |
| 33 delete view_; // TODO(jam): need to do anything else? |
| 34 |
| 35 view_ = new RenderWidgetHostViewWin(render_widget_host); |
| 36 view_->Show(); |
| 37 return view_; |
| 38 } |
| 39 |
| 40 gfx::NativeView TabContentsViewWin::GetNativeView() const { |
| 41 return hwnd(); |
| 42 } |
| 43 |
| 44 gfx::NativeView TabContentsViewWin::GetContentNativeView() const { |
| 45 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); |
| 46 return rwhv ? rwhv->GetNativeView() : NULL; |
| 47 } |
| 48 |
| 49 gfx::NativeWindow TabContentsViewWin::GetTopLevelNativeWindow() const { |
| 50 // TODO(jam): return parent! |
| 51 return NULL; |
| 52 } |
| 53 |
| 54 void TabContentsViewWin::GetContainerBounds(gfx::Rect *out) const { |
| 55 // Copied from NativeWidgetWin::GetClientAreaScreenBounds(). |
| 56 RECT r; |
| 57 GetClientRect(hwnd(), &r); |
| 58 POINT point = { r.left, r.top }; |
| 59 ClientToScreen(hwnd(), &point); |
| 60 *out = gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); |
| 61 } |
| 62 |
| 63 void TabContentsViewWin::SetPageTitle(const std::wstring& title) { |
| 64 } |
| 65 |
| 66 void TabContentsViewWin::OnTabCrashed(base::TerminationStatus status, |
| 67 int error_code) { |
| 68 } |
| 69 |
| 70 void TabContentsViewWin::SizeContents(const gfx::Size& size) { |
| 71 gfx::Rect bounds; |
| 72 GetContainerBounds(&bounds); |
| 73 if (bounds.size() != size) { |
| 74 SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(), |
| 75 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); |
| 76 } else { |
| 77 // Our size matches what we want but the renderers size may not match. |
| 78 // Pretend we were resized so that the renderers size is updated too. |
| 79 if (tab_contents_->interstitial_page()) |
| 80 tab_contents_->interstitial_page()->SetSize(size); |
| 81 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); |
| 82 if (rwhv) |
| 83 rwhv->SetSize(size); |
| 84 } |
| 85 } |
| 86 |
| 87 void TabContentsViewWin::RenderViewCreated(RenderViewHost* host) { |
| 88 } |
| 89 |
| 90 void TabContentsViewWin::Focus() { |
| 91 if (tab_contents_->interstitial_page()) { |
| 92 tab_contents_->interstitial_page()->Focus(); |
| 93 return; |
| 94 } |
| 95 |
| 96 if (tab_contents_->constrained_window_count() > 0) { |
| 97 ConstrainedWindow* window = *tab_contents_->constrained_window_begin(); |
| 98 DCHECK(window); |
| 99 window->FocusConstrainedWindow(); |
| 100 return; |
| 101 } |
| 102 |
| 103 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); |
| 104 if (rwhv) { |
| 105 rwhv->Focus(); |
| 106 } else { |
| 107 SetFocus(hwnd()); |
| 108 } |
| 109 } |
| 110 |
| 111 void TabContentsViewWin::SetInitialFocus() { |
| 112 if (tab_contents_->FocusLocationBarByDefault()) |
| 113 tab_contents_->SetFocusToLocationBar(false); |
| 114 else |
| 115 Focus(); |
| 116 } |
| 117 |
| 118 void TabContentsViewWin::StoreFocus() { |
| 119 // TODO(jam): why is this on TabContentsView? |
| 120 NOTREACHED(); |
| 121 } |
| 122 |
| 123 void TabContentsViewWin::RestoreFocus() { |
| 124 NOTREACHED(); |
| 125 } |
| 126 |
| 127 bool TabContentsViewWin::IsDoingDrag() const { |
| 128 return false; |
| 129 } |
| 130 |
| 131 void TabContentsViewWin::CancelDragAndCloseTab() { |
| 132 } |
| 133 |
| 134 bool TabContentsViewWin::IsEventTracking() const { |
| 135 return false; |
| 136 } |
| 137 |
| 138 void TabContentsViewWin::CloseTabAfterEventTracking() { |
| 139 } |
| 140 |
| 141 void TabContentsViewWin::GetViewBounds(gfx::Rect* out) const { |
| 142 RECT r; |
| 143 GetWindowRect(hwnd(), &r); |
| 144 *out = gfx::Rect(r); |
| 145 } |
| 146 |
| 147 void TabContentsViewWin::CreateNewWindow( |
| 148 int route_id, |
| 149 const ViewHostMsg_CreateWindow_Params& params) { |
| 150 NOTIMPLEMENTED(); |
| 151 } |
| 152 |
| 153 |
| 154 void TabContentsViewWin::CreateNewWidget(int route_id, |
| 155 WebKit::WebPopupType popup_type) { |
| 156 NOTIMPLEMENTED(); |
| 157 } |
| 158 |
| 159 void TabContentsViewWin::CreateNewFullscreenWidget(int route_id) { |
| 160 NOTIMPLEMENTED(); |
| 161 } |
| 162 |
| 163 void TabContentsViewWin::ShowCreatedWindow(int route_id, |
| 164 WindowOpenDisposition disposition, |
| 165 const gfx::Rect& initial_pos, |
| 166 bool user_gesture) { |
| 167 NOTIMPLEMENTED(); |
| 168 } |
| 169 |
| 170 void TabContentsViewWin::ShowCreatedWidget(int route_id, |
| 171 const gfx::Rect& initial_pos) { |
| 172 NOTIMPLEMENTED(); |
| 173 } |
| 174 |
| 175 void TabContentsViewWin::ShowCreatedFullscreenWidget(int route_id) { |
| 176 NOTIMPLEMENTED(); |
| 177 } |
| 178 |
| 179 void TabContentsViewWin::ShowContextMenu(const ContextMenuParams& params) { |
| 180 NOTIMPLEMENTED(); |
| 181 } |
| 182 |
| 183 void TabContentsViewWin::ShowPopupMenu(const gfx::Rect& bounds, |
| 184 int item_height, |
| 185 double item_font_size, |
| 186 int selected_item, |
| 187 const std::vector<WebMenuItem>& items, |
| 188 bool right_aligned) { |
| 189 NOTIMPLEMENTED(); |
| 190 } |
| 191 |
| 192 void TabContentsViewWin::StartDragging(const WebDropData& drop_data, |
| 193 WebKit::WebDragOperationsMask operations, |
| 194 const SkBitmap& image, |
| 195 const gfx::Point& image_offset) { |
| 196 NOTIMPLEMENTED(); |
| 197 } |
| 198 |
| 199 void TabContentsViewWin::UpdateDragCursor(WebKit::WebDragOperation operation) { |
| 200 NOTIMPLEMENTED(); |
| 201 } |
| 202 |
| 203 void TabContentsViewWin::GotFocus() { |
| 204 if (tab_contents_->delegate()) |
| 205 tab_contents_->delegate()->TabContentsFocused(tab_contents_); |
| 206 } |
| 207 |
| 208 void TabContentsViewWin::TakeFocus(bool reverse) { |
| 209 if (tab_contents_->delegate()) |
| 210 tab_contents_->delegate()->TakeFocus(reverse); |
| 211 } |
| 212 |
| 213 LRESULT TabContentsViewWin::OnClose(UINT message, |
| 214 WPARAM wparam, |
| 215 LPARAM lparam, |
| 216 BOOL& handled) { |
| 217 MessageLoop::current()->Quit(); |
| 218 return 0; |
| 219 } |
OLD | NEW |