Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: chrome/renderer/render_widget.cc

Issue 2976008: Bar (Closed)
Patch Set: rebase Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/surface/transport_dib.h" 7 #include "app/surface/transport_dib.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // which case we do not want to unfocus ourself. 364 // which case we do not want to unfocus ourself.
365 if (!has_focus_ && webwidget_) 365 if (!has_focus_ && webwidget_)
366 webwidget_->setFocus(false); 366 webwidget_->setFocus(false);
367 } 367 }
368 368
369 void RenderWidget::PaintRect(const gfx::Rect& rect, 369 void RenderWidget::PaintRect(const gfx::Rect& rect,
370 const gfx::Point& canvas_origin, 370 const gfx::Point& canvas_origin,
371 skia::PlatformCanvas* canvas) { 371 skia::PlatformCanvas* canvas) {
372 canvas->save(); 372 canvas->save();
373 373
374 //CGContextRef cg_context = canvas->getTopPlatformDevice().GetBitmapContext();
375 //CGContextSaveGState(cg_context);
376 //CGContextScaleCTM(cg_context, 0.2, 0.2);
377
374 // Bring the canvas into the coordinate system of the paint rect. 378 // Bring the canvas into the coordinate system of the paint rect.
375 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()), 379 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
376 static_cast<SkScalar>(-canvas_origin.y())); 380 static_cast<SkScalar>(-canvas_origin.y()));
377 381
378 // If there is a custom background, tile it. 382 // If there is a custom background, tile it.
379 if (!background_.empty()) { 383 if (!background_.empty()) {
380 SkPaint paint; 384 SkPaint paint;
381 SkShader* shader = SkShader::CreateBitmapShader(background_, 385 SkShader* shader = SkShader::CreateBitmapShader(background_,
382 SkShader::kRepeat_TileMode, 386 SkShader::kRepeat_TileMode,
383 SkShader::kRepeat_TileMode); 387 SkShader::kRepeat_TileMode);
384 paint.setShader(shader)->unref(); 388 paint.setShader(shader)->unref();
385 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); 389 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
386 canvas->drawPaint(paint); 390 canvas->drawPaint(paint);
387 } 391 }
388 392
389 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); 393 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
390 394
391 PaintDebugBorder(rect, canvas); 395 PaintDebugBorder(rect, canvas);
392 396
393 // Flush to underlying bitmap. TODO(darin): is this needed? 397 // Flush to underlying bitmap. TODO(darin): is this needed?
394 canvas->getTopPlatformDevice().accessBitmap(false); 398 canvas->getTopPlatformDevice().accessBitmap(false);
395 399
400 //CGContextRestoreGState(cg_context);
401
396 canvas->restore(); 402 canvas->restore();
397 } 403 }
398 404
399 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, 405 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
400 skia::PlatformCanvas* canvas) { 406 skia::PlatformCanvas* canvas) {
401 static bool kPaintBorder = 407 static bool kPaintBorder =
402 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); 408 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
403 if (!kPaintBorder) 409 if (!kPaintBorder)
404 return; 410 return;
405 411
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 741 }
736 742
737 void RenderWidget::OnImeConfirmComposition() { 743 void RenderWidget::OnImeConfirmComposition() {
738 if (webwidget_) 744 if (webwidget_)
739 webwidget_->confirmComposition(); 745 webwidget_->confirmComposition();
740 } 746 }
741 747
742 // This message causes the renderer to render an image of the 748 // This message causes the renderer to render an image of the
743 // desired_size, regardless of whether the tab is hidden or not. 749 // desired_size, regardless of whether the tab is hidden or not.
744 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, 750 void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
751 int sequence_num,
745 const gfx::Size& page_size, 752 const gfx::Size& page_size,
746 const gfx::Size& desired_size) { 753 const gfx::Size& desired_size) {
747 if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue()) 754 if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue())
748 return; 755 return;
749 756
750 if (page_size.IsEmpty() || desired_size.IsEmpty()) { 757 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
751 // If one of these is empty, then we just return the dib we were 758 // If one of these is empty, then we just return the dib we were
752 // given, to avoid leaking it. 759 // given, to avoid leaking it.
753 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, 760 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_,
754 dib_handle, 761 sequence_num,
755 desired_size)); 762 desired_size));
756 return; 763 return;
757 } 764 }
758 765
759 // Map the given DIB ID into this process, and unmap it at the end 766 // Map the given DIB ID into this process, and unmap it at the end
760 // of this function. 767 // of this function.
761 scoped_ptr<TransportDIB> paint_at_size_buffer(TransportDIB::Map(dib_handle)); 768 scoped_ptr<TransportDIB> paint_at_size_buffer(TransportDIB::Map(dib_handle));
762 769
763 DCHECK(paint_at_size_buffer.get()); 770 DCHECK(paint_at_size_buffer.get());
764 if (!paint_at_size_buffer.get()) 771 if (!paint_at_size_buffer.get())
(...skipping 18 matching lines...) Expand all
783 return; 790 return;
784 } 791 }
785 792
786 // Reset bounds to what we actually received, but they should be the 793 // Reset bounds to what we actually received, but they should be the
787 // same. 794 // same.
788 DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); 795 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
789 DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); 796 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
790 bounds.set_width(canvas->getDevice()->width()); 797 bounds.set_width(canvas->getDevice()->width());
791 bounds.set_height(canvas->getDevice()->height()); 798 bounds.set_height(canvas->getDevice()->height());
792 799
800 // Add the scale factor to the canvas, so that we'll get the desired size.
801 //#if WEBKIT_USING_SKIA
793 canvas->save(); 802 canvas->save();
794 // Add the scale factor to the canvas, so that we'll get the desired size.
795 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale)); 803 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
804 //#else
805 // Scaling the canvas would draw at normal size and then scale the pixels
806 // down, so that only the upper left image is filled. Scale CG equivalent
807 // instead.
808 // ToWebCanvas: canvas->getTopPlatformDevice().GetBitmapContext();
809 // typedef struct CGContext WebCanvas;
810
811 // WebKit's WebFrameImpl:
812 // GraphicsContext gc(canvas);
813
814 //CGContextRef cg_context = canvas->getTopPlatformDevice().GetBitmapContext();
815 //fprintf(stderr, "context a %f %f: %p\n", x_scale, y_scale, cg_context);
816 //CGContextSaveGState(cg_context);
817 //CGContextScaleCTM(cg_context, x_scale, y_scale);
818
819 //CGContextTranslateCTM(cg_context, 500, 500);
820
821 //#endif
796 822
797 // Have to make sure we're laid out at the right size before 823 // Have to make sure we're laid out at the right size before
798 // rendering. 824 // rendering.
799 gfx::Size old_size = webwidget_->size(); 825 gfx::Size old_size = webwidget_->size();
800 webwidget_->resize(page_size); 826 webwidget_->resize(page_size);
801 webwidget_->layout(); 827 webwidget_->layout();
802 828
803 // Paint the entire thing (using original bounds, not scaled bounds). 829 // Paint the entire thing (using original bounds, not scaled bounds).
830 //orig_bounds.set_width(orig_bounds.width() / x_scale);
831 //orig_bounds.set_height(orig_bounds.height() / y_scale);
804 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); 832 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
833 //#if WEBKIT_USING_SKIA
805 canvas->restore(); 834 canvas->restore();
835 //#else
836 //CGContextRestoreGState(cg_context);
837 //#endif
806 838
807 // Return the widget to its previous size. 839 // Return the widget to its previous size.
808 webwidget_->resize(old_size); 840 webwidget_->resize(old_size);
809 841
810 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, dib_handle, bounds.size())); 842 Send(new ViewHostMsg_PaintAtSize_ACK(
843 routing_id_, sequence_num, bounds.size()));
811 } 844 }
812 845
813 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { 846 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
814 // During shutdown we can just ignore this message. 847 // During shutdown we can just ignore this message.
815 if (!webwidget_) 848 if (!webwidget_)
816 return; 849 return;
817 850
818 set_next_paint_is_repaint_ack(); 851 set_next_paint_is_repaint_ack();
819 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); 852 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
820 didInvalidateRect(repaint_rect); 853 didInvalidateRect(repaint_rect);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 959
927 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { 960 void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
928 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); 961 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
929 i != plugin_window_moves_.end(); ++i) { 962 i != plugin_window_moves_.end(); ++i) {
930 if (i->window == window) { 963 if (i->window == window) {
931 plugin_window_moves_.erase(i); 964 plugin_window_moves_.erase(i);
932 break; 965 break;
933 } 966 }
934 } 967 }
935 } 968 }
OLDNEW
« no previous file with comments | « chrome/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698