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" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 CompleteInit(parent); | 174 CompleteInit(parent); |
175 } | 175 } |
176 | 176 |
177 void RenderWidget::OnClose() { | 177 void RenderWidget::OnClose() { |
178 if (closing_) | 178 if (closing_) |
179 return; | 179 return; |
180 closing_ = true; | 180 closing_ = true; |
181 | 181 |
182 // Browser correspondence is no longer needed at this point. | 182 // Browser correspondence is no longer needed at this point. |
183 if (routing_id_ != MSG_ROUTING_NONE) | 183 if (routing_id_ != MSG_ROUTING_NONE) { |
184 render_thread_->RemoveRoute(routing_id_); | 184 render_thread_->RemoveRoute(routing_id_); |
| 185 SetHidden(false); |
| 186 } |
185 | 187 |
186 // If there is a Send call on the stack, then it could be dangerous to close | 188 // If there is a Send call on the stack, then it could be dangerous to close |
187 // now. Post a task that only gets invoked when there are no nested message | 189 // now. Post a task that only gets invoked when there are no nested message |
188 // loops. | 190 // loops. |
189 MessageLoop::current()->PostNonNestableTask(FROM_HERE, | 191 MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
190 NewRunnableMethod(this, &RenderWidget::Close)); | 192 NewRunnableMethod(this, &RenderWidget::Close)); |
191 | 193 |
192 // Balances the AddRef taken when we called AddRoute. | 194 // Balances the AddRef taken when we called AddRoute. |
193 Release(); | 195 Release(); |
194 } | 196 } |
195 | 197 |
196 void RenderWidget::OnResize(const gfx::Size& new_size, | 198 void RenderWidget::OnResize(const gfx::Size& new_size, |
197 const gfx::Rect& resizer_rect) { | 199 const gfx::Rect& resizer_rect) { |
198 // During shutdown we can just ignore this message. | 200 // During shutdown we can just ignore this message. |
199 if (!webwidget_) | 201 if (!webwidget_) |
200 return; | 202 return; |
201 | 203 |
202 // Remember the rect where the resize corner will be drawn. | 204 // Remember the rect where the resize corner will be drawn. |
203 resizer_rect_ = resizer_rect; | 205 resizer_rect_ = resizer_rect; |
204 | 206 |
205 // TODO(darin): We should not need to reset this here. | 207 // TODO(darin): We should not need to reset this here. |
206 is_hidden_ = false; | 208 SetHidden(false); |
207 needs_repainting_on_restore_ = false; | 209 needs_repainting_on_restore_ = false; |
208 | 210 |
209 // We shouldn't be asked to resize to our current size. | 211 // We shouldn't be asked to resize to our current size. |
210 DCHECK(size_ != new_size); | 212 DCHECK(size_ != new_size); |
211 size_ = new_size; | 213 size_ = new_size; |
212 | 214 |
213 // We should not be sent a Resize message if we have not ACK'd the previous | 215 // We should not be sent a Resize message if we have not ACK'd the previous |
214 DCHECK(!next_paint_is_resize_ack()); | 216 DCHECK(!next_paint_is_resize_ack()); |
215 | 217 |
216 // When resizing, we want to wait to paint before ACK'ing the resize. This | 218 // When resizing, we want to wait to paint before ACK'ing the resize. This |
217 // ensures that we only resize as fast as we can paint. We only need to send | 219 // ensures that we only resize as fast as we can paint. We only need to send |
218 // an ACK if we are resized to a non-empty rect. | 220 // an ACK if we are resized to a non-empty rect. |
219 webwidget_->resize(new_size); | 221 webwidget_->resize(new_size); |
220 if (!new_size.IsEmpty()) { | 222 if (!new_size.IsEmpty()) { |
221 DCHECK(!paint_rect_.IsEmpty()); | 223 DCHECK(!paint_rect_.IsEmpty()); |
222 | 224 |
223 // This should have caused an invalidation of the entire view. The damaged | 225 // This should have caused an invalidation of the entire view. The damaged |
224 // rect could be larger than new_size if we are being made smaller. | 226 // rect could be larger than new_size if we are being made smaller. |
225 DCHECK_GE(paint_rect_.width(), new_size.width()); | 227 DCHECK_GE(paint_rect_.width(), new_size.width()); |
226 DCHECK_GE(paint_rect_.height(), new_size.height()); | 228 DCHECK_GE(paint_rect_.height(), new_size.height()); |
227 | 229 |
228 // We will send the Resize_ACK flag once we paint again. | 230 // We will send the Resize_ACK flag once we paint again. |
229 set_next_paint_is_resize_ack(); | 231 set_next_paint_is_resize_ack(); |
230 } | 232 } |
231 } | 233 } |
232 | 234 |
233 void RenderWidget::OnWasHidden() { | 235 void RenderWidget::OnWasHidden() { |
234 // Go into a mode where we stop generating paint and scrolling events. | 236 // Go into a mode where we stop generating paint and scrolling events. |
235 is_hidden_ = true; | 237 SetHidden(true); |
236 } | 238 } |
237 | 239 |
238 void RenderWidget::OnWasRestored(bool needs_repainting) { | 240 void RenderWidget::OnWasRestored(bool needs_repainting) { |
239 // During shutdown we can just ignore this message. | 241 // During shutdown we can just ignore this message. |
240 if (!webwidget_) | 242 if (!webwidget_) |
241 return; | 243 return; |
242 | 244 |
243 // See OnWasHidden | 245 // See OnWasHidden |
244 is_hidden_ = false; | 246 SetHidden(false); |
245 | 247 |
246 if (!needs_repainting && !needs_repainting_on_restore_) | 248 if (!needs_repainting && !needs_repainting_on_restore_) |
247 return; | 249 return; |
248 needs_repainting_on_restore_ = false; | 250 needs_repainting_on_restore_ = false; |
249 | 251 |
250 // Tag the next paint as a restore ack, which is picked up by DoDeferredPaint | 252 // Tag the next paint as a restore ack, which is picked up by DoDeferredPaint |
251 // when it sends out the next PaintRect message. | 253 // when it sends out the next PaintRect message. |
252 set_next_paint_is_restore_ack(); | 254 set_next_paint_is_restore_ack(); |
253 | 255 |
254 // Generate a full repaint. | 256 // Generate a full repaint. |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); | 731 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
730 didInvalidateRect(repaint_rect); | 732 didInvalidateRect(repaint_rect); |
731 } | 733 } |
732 | 734 |
733 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { | 735 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
734 if (!webwidget_) | 736 if (!webwidget_) |
735 return; | 737 return; |
736 webwidget_->setTextDirection(direction); | 738 webwidget_->setTextDirection(direction); |
737 } | 739 } |
738 | 740 |
| 741 void RenderWidget::SetHidden(bool hidden) { |
| 742 if (is_hidden_ == hidden) |
| 743 return; |
| 744 |
| 745 // The status has changed. Tell the RenderThread about it. |
| 746 is_hidden_ = hidden; |
| 747 if (is_hidden_) |
| 748 render_thread_->WidgetHidden(); |
| 749 else |
| 750 render_thread_->WidgetRestored(); |
| 751 } |
| 752 |
739 void RenderWidget::SetBackground(const SkBitmap& background) { | 753 void RenderWidget::SetBackground(const SkBitmap& background) { |
740 background_ = background; | 754 background_ = background; |
741 // Generate a full repaint. | 755 // Generate a full repaint. |
742 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); | 756 didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
743 } | 757 } |
744 | 758 |
745 bool RenderWidget::next_paint_is_resize_ack() const { | 759 bool RenderWidget::next_paint_is_resize_ack() const { |
746 return ViewHostMsg_PaintRect_Flags::is_resize_ack(next_paint_flags_); | 760 return ViewHostMsg_PaintRect_Flags::is_resize_ack(next_paint_flags_); |
747 } | 761 } |
748 | 762 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 | 868 |
855 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { | 869 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
856 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); | 870 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
857 i != plugin_window_moves_.end(); ++i) { | 871 i != plugin_window_moves_.end(); ++i) { |
858 if (i->window == window) { | 872 if (i->window == window) { |
859 plugin_window_moves_.erase(i); | 873 plugin_window_moves_.erase(i); |
860 break; | 874 break; |
861 } | 875 } |
862 } | 876 } |
863 } | 877 } |
OLD | NEW |