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

Side by Side Diff: chrome/browser/ui/views/frame/opaque_browser_frame_view.cc

Issue 22891016: Add support for rect-based event targeting in views (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch for landing Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 24 matching lines...) Expand all
35 #include "ui/base/accessibility/accessible_view_state.h" 35 #include "ui/base/accessibility/accessible_view_state.h"
36 #include "ui/base/hit_test.h" 36 #include "ui/base/hit_test.h"
37 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/base/resource/resource_bundle.h" 38 #include "ui/base/resource/resource_bundle.h"
39 #include "ui/base/theme_provider.h" 39 #include "ui/base/theme_provider.h"
40 #include "ui/gfx/canvas.h" 40 #include "ui/gfx/canvas.h"
41 #include "ui/gfx/font.h" 41 #include "ui/gfx/font.h"
42 #include "ui/gfx/image/image.h" 42 #include "ui/gfx/image/image.h"
43 #include "ui/gfx/image/image_skia.h" 43 #include "ui/gfx/image/image_skia.h"
44 #include "ui/gfx/path.h" 44 #include "ui/gfx/path.h"
45 #include "ui/gfx/rect_conversions.h"
45 #include "ui/views/controls/button/image_button.h" 46 #include "ui/views/controls/button/image_button.h"
46 #include "ui/views/controls/image_view.h" 47 #include "ui/views/controls/image_view.h"
47 #include "ui/views/controls/label.h" 48 #include "ui/views/controls/label.h"
48 #include "ui/views/layout/layout_constants.h" 49 #include "ui/views/layout/layout_constants.h"
49 #include "ui/views/widget/root_view.h" 50 #include "ui/views/widget/root_view.h"
50 #include "ui/views/window/frame_background.h" 51 #include "ui/views/window/frame_background.h"
51 #include "ui/views/window/window_shape.h" 52 #include "ui/views/window/window_shape.h"
52 53
53 using content::WebContents; 54 using content::WebContents;
54 55
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 PaintRestoredClientEdge(canvas); 324 PaintRestoredClientEdge(canvas);
324 } 325 }
325 326
326 bool OpaqueBrowserFrameView::HitTestRect(const gfx::Rect& rect) const { 327 bool OpaqueBrowserFrameView::HitTestRect(const gfx::Rect& rect) const {
327 if (!views::View::HitTestRect(rect)) { 328 if (!views::View::HitTestRect(rect)) {
328 // |rect| is outside OpaqueBrowserFrameView's bounds. 329 // |rect| is outside OpaqueBrowserFrameView's bounds.
329 return false; 330 return false;
330 } 331 }
331 332
332 // If the rect is outside the bounds of the client area, claim it. 333 // If the rect is outside the bounds of the client area, claim it.
333 // TODO(tdanderson): Implement View::ConvertRectToTarget(). 334 gfx::RectF rect_in_client_view_coords_f(rect);
334 gfx::Point rect_in_client_view_coords_origin(rect.origin()); 335 View::ConvertRectToTarget(this, frame()->client_view(),
335 View::ConvertPointToTarget(this, frame()->client_view(), 336 &rect_in_client_view_coords_f);
336 &rect_in_client_view_coords_origin); 337 gfx::Rect rect_in_client_view_coords = gfx::ToEnclosingRect(
337 gfx::Rect rect_in_client_view_coords( 338 rect_in_client_view_coords_f);
338 rect_in_client_view_coords_origin, rect.size());
339 if (!frame()->client_view()->HitTestRect(rect_in_client_view_coords)) 339 if (!frame()->client_view()->HitTestRect(rect_in_client_view_coords))
340 return true; 340 return true;
341 341
342 // Otherwise, claim |rect| only if it is above the bottom of the tabstrip in 342 // Otherwise, claim |rect| only if it is above the bottom of the tabstrip in
343 // a non-tab portion. 343 // a non-tab portion.
344 TabStrip* tabstrip = browser_view()->tabstrip(); 344 TabStrip* tabstrip = browser_view()->tabstrip();
345 if (!tabstrip || !browser_view()->IsTabStripVisible()) 345 if (!tabstrip || !browser_view()->IsTabStripVisible())
346 return false; 346 return false;
347 347
348 gfx::Point rect_in_tabstrip_coords_origin(rect.origin()); 348 gfx::RectF rect_in_tabstrip_coords_f(rect);
349 View::ConvertPointToTarget(this, tabstrip, 349 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f);
350 &rect_in_tabstrip_coords_origin); 350 gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect(
351 gfx::Rect rect_in_tabstrip_coords( 351 rect_in_tabstrip_coords_f);
352 rect_in_tabstrip_coords_origin, rect.size());
353
354 if (rect_in_tabstrip_coords.bottom() > tabstrip->GetLocalBounds().bottom()) { 352 if (rect_in_tabstrip_coords.bottom() > tabstrip->GetLocalBounds().bottom()) {
355 // |rect| is below the tabstrip. 353 // |rect| is below the tabstrip.
356 return false; 354 return false;
357 } 355 }
358 356
359 if (tabstrip->HitTestRect(rect_in_tabstrip_coords)) { 357 if (tabstrip->HitTestRect(rect_in_tabstrip_coords)) {
360 // Claim |rect| if it is in a non-tab portion of the tabstrip. 358 // Claim |rect| if it is in a non-tab portion of the tabstrip.
361 // TODO(tdanderson): Pass |rect_in_tabstrip_coords| instead of its center 359 return tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords);
362 // point to TabStrip::IsPositionInWindowCaption() once
363 // GetEventHandlerForRect() is implemented.
364 return tabstrip->IsPositionInWindowCaption(
365 rect_in_tabstrip_coords.CenterPoint());
366 } 360 }
367 361
368 // The window switcher button is to the right of the tabstrip but is 362 // The window switcher button is to the right of the tabstrip but is
369 // part of the client view. 363 // part of the client view.
370 views::View* window_switcher_button = 364 views::View* window_switcher_button =
371 browser_view()->window_switcher_button(); 365 browser_view()->window_switcher_button();
372 if (window_switcher_button && window_switcher_button->visible()) { 366 if (window_switcher_button && window_switcher_button->visible()) {
373 gfx::Point rect_in_window_switcher_coords_origin(rect.origin()); 367 gfx::RectF rect_in_window_switcher_coords_f(rect);
374 View::ConvertPointToTarget(this, window_switcher_button, 368 View::ConvertRectToTarget(this, window_switcher_button,
375 &rect_in_window_switcher_coords_origin); 369 &rect_in_window_switcher_coords_f);
376 gfx::Rect rect_in_window_switcher_coords( 370 gfx::Rect rect_in_window_switcher_coords = gfx::ToEnclosingRect(
377 rect_in_window_switcher_coords_origin, rect.size()); 371 rect_in_window_switcher_coords_f);
378 372
379 if (window_switcher_button->HitTestRect(rect_in_window_switcher_coords)) 373 if (window_switcher_button->HitTestRect(rect_in_window_switcher_coords))
380 return false; 374 return false;
381 } 375 }
382 376
383 // We claim |rect| because it is above the bottom of the tabstrip, but 377 // We claim |rect| because it is above the bottom of the tabstrip, but
384 // neither in the tabstrip nor in the window switcher button. In particular, 378 // neither in the tabstrip nor in the window switcher button. In particular,
385 // the avatar label/button is left of the tabstrip and the window controls 379 // the avatar label/button is left of the tabstrip and the window controls
386 // are right of the tabstrip. 380 // are right of the tabstrip.
387 return true; 381 return true;
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 879
886 int OpaqueBrowserFrameView::GetTopAreaHeight() const { 880 int OpaqueBrowserFrameView::GetTopAreaHeight() const {
887 gfx::ImageSkia* frame_image = GetFrameImage(); 881 gfx::ImageSkia* frame_image = GetFrameImage();
888 int top_area_height = frame_image->height(); 882 int top_area_height = frame_image->height();
889 if (browser_view()->IsTabStripVisible()) { 883 if (browser_view()->IsTabStripVisible()) {
890 top_area_height = std::max(top_area_height, 884 top_area_height = std::max(top_area_height,
891 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom()); 885 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom());
892 } 886 }
893 return top_area_height; 887 return top_area_height;
894 } 888 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698