| OLD | NEW |
| 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/tabs/tab.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation, | 195 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation, |
| 196 public gfx::AnimationDelegate { | 196 public gfx::AnimationDelegate { |
| 197 public: | 197 public: |
| 198 explicit FaviconCrashAnimation(Tab* target) | 198 explicit FaviconCrashAnimation(Tab* target) |
| 199 : gfx::LinearAnimation(1000, 25, this), | 199 : gfx::LinearAnimation(1000, 25, this), |
| 200 target_(target) { | 200 target_(target) { |
| 201 } | 201 } |
| 202 virtual ~FaviconCrashAnimation() {} | 202 virtual ~FaviconCrashAnimation() {} |
| 203 | 203 |
| 204 // gfx::Animation overrides: | 204 // gfx::Animation overrides: |
| 205 virtual void AnimateToState(double state) OVERRIDE { | 205 virtual void AnimateToState(double state) override { |
| 206 const double kHidingOffset = 27; | 206 const double kHidingOffset = 27; |
| 207 | 207 |
| 208 if (state < .5) { | 208 if (state < .5) { |
| 209 target_->SetFaviconHidingOffset( | 209 target_->SetFaviconHidingOffset( |
| 210 static_cast<int>(floor(kHidingOffset * 2.0 * state))); | 210 static_cast<int>(floor(kHidingOffset * 2.0 * state))); |
| 211 } else { | 211 } else { |
| 212 target_->DisplayCrashedFavicon(); | 212 target_->DisplayCrashedFavicon(); |
| 213 target_->SetFaviconHidingOffset( | 213 target_->SetFaviconHidingOffset( |
| 214 static_cast<int>( | 214 static_cast<int>( |
| 215 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset)))); | 215 floor(kHidingOffset - ((state - .5) * 2.0 * kHidingOffset)))); |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 // gfx::AnimationDelegate overrides: | 219 // gfx::AnimationDelegate overrides: |
| 220 virtual void AnimationCanceled(const gfx::Animation* animation) OVERRIDE { | 220 virtual void AnimationCanceled(const gfx::Animation* animation) override { |
| 221 target_->SetFaviconHidingOffset(0); | 221 target_->SetFaviconHidingOffset(0); |
| 222 } | 222 } |
| 223 | 223 |
| 224 private: | 224 private: |
| 225 Tab* target_; | 225 Tab* target_; |
| 226 | 226 |
| 227 DISALLOW_COPY_AND_ASSIGN(FaviconCrashAnimation); | 227 DISALLOW_COPY_AND_ASSIGN(FaviconCrashAnimation); |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 //////////////////////////////////////////////////////////////////////////////// | 230 //////////////////////////////////////////////////////////////////////////////// |
| 231 // TabCloseButton | 231 // TabCloseButton |
| 232 // | 232 // |
| 233 // This is a Button subclass that causes middle clicks to be forwarded to the | 233 // This is a Button subclass that causes middle clicks to be forwarded to the |
| 234 // parent View by explicitly not handling them in OnMousePressed. | 234 // parent View by explicitly not handling them in OnMousePressed. |
| 235 class Tab::TabCloseButton : public views::ImageButton, | 235 class Tab::TabCloseButton : public views::ImageButton, |
| 236 public views::MaskedTargeterDelegate { | 236 public views::MaskedTargeterDelegate { |
| 237 public: | 237 public: |
| 238 explicit TabCloseButton(Tab* tab) | 238 explicit TabCloseButton(Tab* tab) |
| 239 : views::ImageButton(tab), | 239 : views::ImageButton(tab), |
| 240 tab_(tab) { | 240 tab_(tab) { |
| 241 SetEventTargeter( | 241 SetEventTargeter( |
| 242 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); | 242 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); |
| 243 } | 243 } |
| 244 | 244 |
| 245 virtual ~TabCloseButton() {} | 245 virtual ~TabCloseButton() {} |
| 246 | 246 |
| 247 // views::View: | 247 // views::View: |
| 248 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) OVERRIDE { | 248 virtual View* GetTooltipHandlerForPoint(const gfx::Point& point) override { |
| 249 // Tab close button has no children, so tooltip handler should be the same | 249 // Tab close button has no children, so tooltip handler should be the same |
| 250 // as the event handler. | 250 // as the event handler. |
| 251 // In addition, a hit test has to be performed for the point (as | 251 // In addition, a hit test has to be performed for the point (as |
| 252 // GetTooltipHandlerForPoint() is responsible for it). | 252 // GetTooltipHandlerForPoint() is responsible for it). |
| 253 if (!HitTestPoint(point)) | 253 if (!HitTestPoint(point)) |
| 254 return NULL; | 254 return NULL; |
| 255 return GetEventHandlerForPoint(point); | 255 return GetEventHandlerForPoint(point); |
| 256 } | 256 } |
| 257 | 257 |
| 258 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { | 258 virtual bool OnMousePressed(const ui::MouseEvent& event) override { |
| 259 tab_->controller_->OnMouseEventInTab(this, event); | 259 tab_->controller_->OnMouseEventInTab(this, event); |
| 260 | 260 |
| 261 bool handled = ImageButton::OnMousePressed(event); | 261 bool handled = ImageButton::OnMousePressed(event); |
| 262 // Explicitly mark midle-mouse clicks as non-handled to ensure the tab | 262 // Explicitly mark midle-mouse clicks as non-handled to ensure the tab |
| 263 // sees them. | 263 // sees them. |
| 264 return event.IsOnlyMiddleMouseButton() ? false : handled; | 264 return event.IsOnlyMiddleMouseButton() ? false : handled; |
| 265 } | 265 } |
| 266 | 266 |
| 267 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE { | 267 virtual void OnMouseMoved(const ui::MouseEvent& event) override { |
| 268 tab_->controller_->OnMouseEventInTab(this, event); | 268 tab_->controller_->OnMouseEventInTab(this, event); |
| 269 CustomButton::OnMouseMoved(event); | 269 CustomButton::OnMouseMoved(event); |
| 270 } | 270 } |
| 271 | 271 |
| 272 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE { | 272 virtual void OnMouseReleased(const ui::MouseEvent& event) override { |
| 273 tab_->controller_->OnMouseEventInTab(this, event); | 273 tab_->controller_->OnMouseEventInTab(this, event); |
| 274 CustomButton::OnMouseReleased(event); | 274 CustomButton::OnMouseReleased(event); |
| 275 } | 275 } |
| 276 | 276 |
| 277 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { | 277 virtual void OnGestureEvent(ui::GestureEvent* event) override { |
| 278 // Consume all gesture events here so that the parent (Tab) does not | 278 // Consume all gesture events here so that the parent (Tab) does not |
| 279 // start consuming gestures. | 279 // start consuming gestures. |
| 280 ImageButton::OnGestureEvent(event); | 280 ImageButton::OnGestureEvent(event); |
| 281 event->SetHandled(); | 281 event->SetHandled(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 virtual const char* GetClassName() const OVERRIDE { | 284 virtual const char* GetClassName() const override { |
| 285 return kTabCloseButtonName; | 285 return kTabCloseButtonName; |
| 286 } | 286 } |
| 287 | 287 |
| 288 private: | 288 private: |
| 289 // Returns the rectangular bounds of parent tab's visible region in the | 289 // Returns the rectangular bounds of parent tab's visible region in the |
| 290 // local coordinate space of |this|. | 290 // local coordinate space of |this|. |
| 291 gfx::Rect GetTabBounds() const { | 291 gfx::Rect GetTabBounds() const { |
| 292 gfx::Path tab_mask; | 292 gfx::Path tab_mask; |
| 293 tab_->GetHitTestMask(&tab_mask); | 293 tab_->GetHitTestMask(&tab_mask); |
| 294 | 294 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 309 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom(); | 309 int bottom_overflow = button_bounds.bottom() - tab_bounds.bottom(); |
| 310 if (top_overflow > 0) | 310 if (top_overflow > 0) |
| 311 button_bounds.set_y(tab_bounds.y()); | 311 button_bounds.set_y(tab_bounds.y()); |
| 312 else if (bottom_overflow > 0) | 312 else if (bottom_overflow > 0) |
| 313 button_bounds.set_height(button_bounds.height() - bottom_overflow); | 313 button_bounds.set_height(button_bounds.height() - bottom_overflow); |
| 314 | 314 |
| 315 return button_bounds; | 315 return button_bounds; |
| 316 } | 316 } |
| 317 | 317 |
| 318 // views::ViewTargeterDelegate: | 318 // views::ViewTargeterDelegate: |
| 319 virtual View* TargetForRect(View* root, const gfx::Rect& rect) OVERRIDE { | 319 virtual View* TargetForRect(View* root, const gfx::Rect& rect) override { |
| 320 CHECK_EQ(root, this); | 320 CHECK_EQ(root, this); |
| 321 | 321 |
| 322 if (!views::UsePointBasedTargeting(rect)) | 322 if (!views::UsePointBasedTargeting(rect)) |
| 323 return ViewTargeterDelegate::TargetForRect(root, rect); | 323 return ViewTargeterDelegate::TargetForRect(root, rect); |
| 324 | 324 |
| 325 // Ignore the padding set on the button. | 325 // Ignore the padding set on the button. |
| 326 gfx::Rect contents_bounds = GetContentsBounds(); | 326 gfx::Rect contents_bounds = GetContentsBounds(); |
| 327 contents_bounds.set_x(GetMirroredXForRect(contents_bounds)); | 327 contents_bounds.set_x(GetMirroredXForRect(contents_bounds)); |
| 328 | 328 |
| 329 // Include the padding in hit-test for touch events. | 329 // Include the padding in hit-test for touch events. |
| 330 if (aura::Env::GetInstance()->is_touch_down()) | 330 if (aura::Env::GetInstance()->is_touch_down()) |
| 331 contents_bounds = GetLocalBounds(); | 331 contents_bounds = GetLocalBounds(); |
| 332 | 332 |
| 333 return contents_bounds.Intersects(rect) ? this : parent(); | 333 return contents_bounds.Intersects(rect) ? this : parent(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 // views:MaskedTargeterDelegate: | 336 // views:MaskedTargeterDelegate: |
| 337 virtual bool GetHitTestMask(gfx::Path* mask) const OVERRIDE { | 337 virtual bool GetHitTestMask(gfx::Path* mask) const override { |
| 338 DCHECK(mask); | 338 DCHECK(mask); |
| 339 mask->reset(); | 339 mask->reset(); |
| 340 | 340 |
| 341 // The parent tab may be partially occluded by another tab if we are | 341 // The parent tab may be partially occluded by another tab if we are |
| 342 // in stacked tab mode, which means that the tab close button may also | 342 // in stacked tab mode, which means that the tab close button may also |
| 343 // be partially occluded. Define the hit test mask of the tab close | 343 // be partially occluded. Define the hit test mask of the tab close |
| 344 // button to be the intersection of the parent tab's visible bounds | 344 // button to be the intersection of the parent tab's visible bounds |
| 345 // and the bounds of the tab close button. | 345 // and the bounds of the tab close button. |
| 346 gfx::Rect tab_bounds(GetTabBounds()); | 346 gfx::Rect tab_bounds(GetTabBounds()); |
| 347 gfx::Rect button_bounds(GetTabCloseButtonBounds(tab_bounds)); | 347 gfx::Rect button_bounds(GetTabCloseButtonBounds(tab_bounds)); |
| 348 gfx::Rect intersection(gfx::IntersectRects(tab_bounds, button_bounds)); | 348 gfx::Rect intersection(gfx::IntersectRects(tab_bounds, button_bounds)); |
| 349 | 349 |
| 350 if (!intersection.IsEmpty()) { | 350 if (!intersection.IsEmpty()) { |
| 351 mask->addRect(RectToSkRect(intersection)); | 351 mask->addRect(RectToSkRect(intersection)); |
| 352 return true; | 352 return true; |
| 353 } | 353 } |
| 354 | 354 |
| 355 return false; | 355 return false; |
| 356 } | 356 } |
| 357 | 357 |
| 358 virtual bool DoesIntersectRect(const View* target, | 358 virtual bool DoesIntersectRect(const View* target, |
| 359 const gfx::Rect& rect) const OVERRIDE { | 359 const gfx::Rect& rect) const override { |
| 360 CHECK_EQ(target, this); | 360 CHECK_EQ(target, this); |
| 361 | 361 |
| 362 // If the request is not made in response to a gesture, use the | 362 // If the request is not made in response to a gesture, use the |
| 363 // default implementation. | 363 // default implementation. |
| 364 if (views::UsePointBasedTargeting(rect)) | 364 if (views::UsePointBasedTargeting(rect)) |
| 365 return MaskedTargeterDelegate::DoesIntersectRect(target, rect); | 365 return MaskedTargeterDelegate::DoesIntersectRect(target, rect); |
| 366 | 366 |
| 367 // The hit test request is in response to a gesture. Return false if any | 367 // The hit test request is in response to a gesture. Return false if any |
| 368 // part of the tab close button is hidden from the user. | 368 // part of the tab close button is hidden from the user. |
| 369 // TODO(tdanderson): Consider always returning the intersection if the | 369 // TODO(tdanderson): Consider always returning the intersection if the |
| (...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1595 const gfx::ImageSkia& image) { | 1595 const gfx::ImageSkia& image) { |
| 1596 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); | 1596 DCHECK_NE(scale_factor, ui::SCALE_FACTOR_NONE); |
| 1597 ImageCacheEntry entry; | 1597 ImageCacheEntry entry; |
| 1598 entry.resource_id = resource_id; | 1598 entry.resource_id = resource_id; |
| 1599 entry.scale_factor = scale_factor; | 1599 entry.scale_factor = scale_factor; |
| 1600 entry.image = image; | 1600 entry.image = image; |
| 1601 image_cache_->push_front(entry); | 1601 image_cache_->push_front(entry); |
| 1602 if (image_cache_->size() > kMaxImageCacheSize) | 1602 if (image_cache_->size() > kMaxImageCacheSize) |
| 1603 image_cache_->pop_back(); | 1603 image_cache_->pop_back(); |
| 1604 } | 1604 } |
| OLD | NEW |